PageSourceSearch

https://starrcompanies.com/-/media/Themes/Starr/Starr/Starr-Base-Theme/Scripts/zoomsection.js

js starrcompanies.com collected 2026-10-02 05:11:09 UTC 11,587 bytes, 419 lines download raw bytes

1/* Detect-zoom
2 * -----------
3 * Cross Browser Zoom and Pixel Ratio Detector
4 * Version 1.0.4 | Apr 1 2013
5 * dual-licensed under the WTFPL and MIT license
6 * Maintained by https://github/tombigel
7 * Original developer https://github.com/yonran
8 */
9
10//AMD and CommonJS initialization copied from https://github.com/zohararad/audio5js
11(function (root, ns, factory) {
12  "use strict";
13
14  if (typeof (module) !== 'undefined' && module.exports) { // CommonJS
15      module.exports = factory(ns, root);
16  } else if (typeof (define) === 'function' && define.amd) { // AMD
17      define("detect-zoom", function () {
18          return factory(ns, root);
19      });
20  } else {
21      root[ns] = factory(ns, root);
22  }
23
24}(window, 'detectZoom', function () {
25
26  /**
27   * Use devicePixelRatio if supported by the browser
28   * @return {Number}
29   * @private
30   */
31  var devicePixelRatio = function () {
32      return window.devicePixelRatio || 1;
33  };
34
35  /**
36   * Fallback function to set default values
37   * @return {Object}
38   * @private
39   */
40  var fallback = function () {
41      return {
42          zoom: 1,
43          devicePxPerCssPx: 1
44      };
45  };
46  /**
47   * IE 8 and 9: no trick needed!
48   * TODO: Test on IE10 and Windows 8 RT
49   * @return {Object}
50   * @private
51   **/
52  var ie8 = function () {
53      var zoom = Math.round((screen.deviceXDPI / screen.logicalXDPI) * 100) / 100;
54      return {
55          zoom: zoom,
56          devicePxPerCssPx: zoom * devicePixelRatio()
57      };
58  };
59
60  /**
61   * For IE10 we need to change our technique again...
62   * thanks https://github.com/stefanvanburen
63   * @return {Object}
64   * @private
65   */
66  var ie10 = function () {
67      var zoom = Math.round((document.documentElement.offsetHeight / window.innerHeight) * 100) / 100;
68      return {
69          zoom: zoom,
70          devicePxPerCssPx: zoom * devicePixelRatio()
71      };
72  };
73
74/**
75* For chrome
76*
77*/
78  var chrome = function()
79  {
80    var zoom = Math.round(((window.outerWidth) / window.innerWidth)*100) / 100;
81      return {
82          zoom: zoom,
83          devicePxPerCssPx: zoom * devicePixelRatio()
84      };	    
85  }
86
87/**
88* For safari (same as chrome)
89*
90*/
91  var safari= function()
92  {
93    var zoom = Math.round(((document.documentElement.clientWidth) / window.innerWidth)*100) / 100;
94      return {
95          zoom: zoom,
96          devicePxPerCssPx: zoom * devicePixelRatio()
97      };	    
98  }
99
100
101  /**
102   * Mobile WebKit
103   * the trick: window.innerWIdth is in CSS pixels, while
104   * screen.width and screen.height are in system pixels.
105   * And there are no scrollbars to mess up the measurement.
106   * @return {Object}
107   * @private
108   */
109  var webkitMobile = function () {
110      var deviceWidth = (Math.abs(window.orientation) == 90) ? screen.height : screen.width;
111      var zoom = deviceWidth / window.innerWidth;
112      return {
113          zoom: zoom,
114          devicePxPerCssPx: zoom * devicePixelRatio()
115      };
116  };
117
118  /**
119   * Desktop Webkit
120   * the trick: an element's clientHeight is in CSS pixels, while you can
121   * set its line-height in system pixels using font-size and
122   * -webkit-text-size-adjust:none.
123   * device-pixel-ratio: http://www.webkit.org/blog/55/high-dpi-web-sites/
124   *
125   * Previous trick (used before http://trac.webkit.org/changeset/100847):
126   * documentElement.scrollWidth is in CSS pixels, while
127   * document.width was in system pixels. Note that this is the
128   * layout width of the document, which is slightly different from viewport
129   * because document width does not include scrollbars and might be wider
130   * due to big elements.
131   * @return {Object}
132   * @private
133   */
134  var webkit = function () {
135      var important = function (str) {
136          return str.replace(/;/g, " !important;");
137      };
138
139      var div = document.createElement('div');
140      div.innerHTML = "1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0";
141      div.setAttribute('style', important('font: 100px/1em sans-serif; -webkit-text-size-adjust: none; text-size-adjust: none; height: auto; width: 1em; padding: 0; overflow: visible;'));
142
143      // The container exists so that the div will be laid out in its own flow
144      // while not impacting the layout, viewport size, or display of the
145      // webpage as a whole.
146      // Add !important and relevant CSS rule resets
147      // so that other rules cannot affect the results.
148      var container = document.createElement('div');
149      container.setAttribute('style', important('width:0; height:0; overflow:hidden; visibility:hidden; position: absolute;'));
150      container.appendChild(div);
151
152      document.body.appendChild(container);
153      var zoom = 1000 / div.clientHeight;
154      zoom = Math.round(zoom * 100) / 100;
155      document.body.removeChild(container);
156
157      return{
158          zoom: zoom,
159          devicePxPerCssPx: zoom * devicePixelRatio()
160      };
161  };
162
163  /**
164   * no real trick; device-pixel-ratio is the ratio of device dpi / css dpi.
165   * (Note that this is a different interpretation than Webkit's device
166   * pixel ratio, which is the ratio device dpi / system dpi).
167   *
168   * Also, for Mozilla, there is no difference between the zoom factor and the device ratio.
169   *
170   * @return {Object}
171   * @private
172   */
173  var firefox4 = function () {
174      var zoom = mediaQueryBinarySearch('min--moz-device-pixel-ratio', '', 0, 10, 20, 0.0001);
175      zoom = Math.round(zoom * 100) / 100;
176      return {
177          zoom: zoom,
178          devicePxPerCssPx: zoom
179      };
180  };
181
182  /**
183   * Firefox 18.x
184   * Mozilla added support for devicePixelRatio to Firefox 18,
185   * but it is affected by the zoom level, so, like in older
186   * Firefox we can't tell if we are in zoom mode or in a device
187   * with a different pixel ratio
188   * @return {Object}
189   * @private
190   */
191  var firefox18 = function () {
192      return {
193          zoom: firefox4().zoom,
194          devicePxPerCssPx: devicePixelRatio()
195      };
196  };
197
198  /**
199   * works starting Opera 11.11
200   * the trick: outerWidth is the viewport width including scrollbars in
201   * system px, while innerWidth is the viewport width including scrollbars
202   * in CSS px
203   * @return {Object}
204   * @private
205   */
206  var opera11 = function () {
207      var zoom = window.top.outerWidth / window.top.innerWidth;
208      zoom = Math.round(zoom * 100) / 100;
209      return {
210          zoom: zoom,
211          devicePxPerCssPx: zoom * devicePixelRatio()
212      };
213  };
214
215  /**
216   * Use a binary search through media queries to find zoom level in Firefox
217   * @param property
218   * @param unit
219   * @param a
220   * @param b
221   * @param maxIter
222   * @param epsilon
223   * @return {Number}
224   */
225  var mediaQueryBinarySearch = function (property, unit, a, b, maxIter, epsilon) {
226      var matchMedia;
227      var head, style, div;
228      if (window.matchMedia) {
229          matchMedia = window.matchMedia;
230      } else {
231          head = document.getElementsByTagName('head')[0];
232          style = document.createElement('style');
233          head.appendChild(style);
234
235          div = document.createElement('div');
236          div.className = 'mediaQueryBinarySearch';
237          div.style.display = 'none';
238          document.body.appendChild(div);
239
240          matchMedia = function (query) {
241              style.sheet.insertRule('@media ' + query + '{.mediaQueryBinarySearch ' + '{text-decoration: underline} }', 0);
242              var matched = getComputedStyle(div, null).textDecoration == 'underline';
243              style.sheet.deleteRule(0);
244              return {matches: matched};
245          };
246      }
247      var ratio = binarySearch(a, b, maxIter);
248      if (div) {
249          head.removeChild(style);
250          document.body.removeChild(div);
251      }
252      return ratio;
253
254      function binarySearch(a, b, maxIter) {
255          var mid = (a + b) / 2;
256          if (maxIter <= 0 || b - a < epsilon) {
257              return mid;
258          }
259          var query = "(" + property + ":" + mid + unit + ")";
260          if (matchMedia(query).matches) {
261              return binarySearch(mid, b, maxIter - 1);
262          } else {
263              return binarySearch(a, mid, maxIter - 1);
264          }
265      }
266  };
267
268  /**
269   * Generate detection function
270   * @private
271   */
272  var detectFunction = (function () {
273      var func = fallback;
274      //IE8+
275      if (!isNaN(screen.logicalXDPI) && !isNaN(screen.systemXDPI)) {
276          func = ie8;
277      }
278      // IE10+ / Touch
279      else if (window.navigator.msMaxTouchPoints) {
280          func = ie10;
281      }
282  //chrome
283  else if(!!window.chrome && !(!!window.opera || navigator.userAgent.indexOf(' Opera') >= 0)){
284    func = chrome;
285  }
286  //safari
287  else if(Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0){
288    func = safari;
289  }	
290      //Mobile Webkit
291      else if ('orientation' in window && 'webkitRequestAnimationFrame' in window) {
292          func = webkitMobile;
293      }
294      //WebKit
295      else if ('webkitRequestAnimationFrame' in window) {
296          func = webkit;
297      }
298      //Opera
299      else if (navigator.userAgent.indexOf('Opera') >= 0) {
300          func = opera11;
301      }
302      //Last one is Firefox
303      //FF 18.x
304      else if (window.devicePixelRatio) {
305          func = firefox18;
306      }
307      //FF 4.0 - 17.x
308      else if (firefox4().zoom > 0.001) {
309          func = firefox4;
310      }
311
312      return func;
313  }());
314
315
316  return ({
317
318      /**
319       * Ratios.zoom shorthand
320       * @return {Number} Zoom level
321       */
322      zoom: function () {
323          return detectFunction().zoom;
324      },
325
326      /**
327       * Ratios.devicePxPerCssPx shorthand
328       * @return {Number} devicePxPerCssPx level
329       */
330      device: function () {
331          return detectFunction().devicePxPerCssPx;
332      }
333  });
334}));
335
336//-----------------------
337// debouncing plugin by Paul Irish https://www.paulirish.com/2009/throttled-smartresize-jquery-event-handler/
338//-----------------------
339(function($,sr){
340var debounce = function (func, threshold, execAsap) {
341    var timeout;
342
343    return function debounced () {
344        var obj = this, args = arguments;
345        function delayed () {
346            if (!execAsap)
347                func.apply(obj, args);
348            timeout = null;
349        };
350
351        if (timeout)
352            clearTimeout(timeout);
353        else if (execAsap)
354            func.apply(obj, args);
355
356        timeout = setTimeout(delayed, threshold || 100);
357    };
358}
359// smartresize 
360jQuery.fn[sr] = function(fn){  return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
361
362})(jQuery,'smartresize');
363
364
365//-----------------------
366// Custom functions
367//-----------------------
368
369var aZoom = $('.a-zoom');
370var dZoom = $('.d-zoom');
371var $body = $("body");
372function getZoomValues () {
373var zoom = detectZoom.zoom();
374var device = detectZoom.device();
375var newZoomVal = parseFloat(zoom,10).toFixed(2);
376var newDeviceVal = parseFloat(device,10).toFixed(2);
377aZoom.text(newZoomVal);
378dZoom.text(newDeviceVal);
379changeBackground(newZoomVal);
380
381}
382
383function changeBackground (zoom) {
384if ( zoom == 1.00) {
385  $(".slidesectionlink").show();
386}else if ( zoom >= 1.10) {
387  $(".slidesectionlink").hide();
388}
389
390else if ( zoom == 0.90) {
391      $(".slidesectionlink").show();
392}
393 else if ( zoom == 0.80) {
394 $(".slidesectionlink").show();
395}
396else if ( zoom == 0.75) {
397 $(".slidesectionlink").show();
398}
399else if ( zoom == 0.67) {
400 $(".slidesectionlink").show();
401}
402else if ( zoom == 0.50) {
403  $(".slidesectionlink").show();
404}
405else if ( zoom == 0.33) {
406  $(".slidesectionlink").show();
407}
408 else if ( zoom == 0.25) {
409  $(".slidesectionlink").show();
410}
411}
412
413$(document).ready(function() {
414getZoomValues();
415});
416$(window).smartresize(function(){
417getZoomValues();
418
419});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.