Subversion Repositories oidplus

Rev

View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  1. /**
  2.  * @preserve jquery.layout.browserZoom 1.0
  3.  * $Date: 2011-12-29 08:00:00 (Thu, 29 Dec 2011) $
  4.  *
  5.  * Copyright (c) 2012
  6.  *   Kevin Dalman (http://allpro.net)
  7.  *
  8.  * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
  9.  * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
  10.  *
  11.  * @dependancies: UI Layout 1.3.0.rc30.1 or higher
  12.  *
  13.  * @support: http://groups.google.com/group/jquery-ui-layout
  14.  *
  15.  * @todo: Extend logic to handle other problematic zooming in browsers
  16.  * @todo: Add hotkey/mousewheel bindings to _instantly_ respond to these zoom event
  17.  */
  18. ;(function ($) {
  19.                        
  20. var _ = $.layout;
  21.  
  22. // tell Layout that the plugin is available
  23. _.plugins.browserZoom = true;
  24.  
  25. _.defaults.browserZoomCheckInterval = 1000;
  26. _.optionsMap.layout.push("browserZoomCheckInterval");
  27.  
  28. /*
  29.  *      browserZoom methods
  30.  */
  31. _.browserZoom = {
  32.  
  33.         _init: function (inst) {
  34.                 $.layout.browserZoom._setTimer(inst);
  35.         }
  36.  
  37. ,       _setTimer: function (inst) {
  38.                 if (inst.destroyed) return;
  39.                 var o = inst.options
  40.                 ,       s = inst.state
  41.                 ,       z = s.browserZoom = $.layout.browserZoom.ratio()
  42.                 ;
  43.                 if (o.resizeWithWindow && z !== false) {
  44.                         setTimeout(function(){
  45.                                 if (inst.destroyed) return;
  46.                                 var d = $.layout.browserZoom.ratio();
  47.                                 if (d !== s.browserZoom) {
  48.                                         s.browserZoom = d;
  49.                                         inst.resizeAll();
  50.                                 }
  51.                                 $.layout.browserZoom._setTimer(inst); // set a NEW timeout
  52.                         },      Math.max( o.browserZoomCheckInterval, 100 )); // MINIMUM 100ms interval, for performance
  53.                 }
  54.         }
  55.  
  56. ,       ratio: function () {
  57.                 var w   = window
  58.                 ,       s       = screen
  59.                 ,       d       = document
  60.                 ,       dE      = d.documentElement || d.body
  61.                 ,       b       = $.layout.browser
  62.                 ,       v       = b.version
  63.                 ,       r, sW, cW
  64.                 ;
  65.                 // we can ignore all browsers that fire window.resize event onZoom
  66.                 if (!b.msie || v > 8)
  67.                         return false; // don't need to track zoom
  68.                 if (s.deviceXDPI)
  69.                         return calc(s.deviceXDPI, s.systemXDPI);
  70.                 // everything below is just for future reference!
  71.                 if (b.webkit && (r = d.body.getBoundingClientRect))
  72.                         return calc((r.left - r.right), d.body.offsetWidth);
  73.                 if (b.webkit && (sW = w.outerWidth))
  74.                         return calc(sW, w.innerWidth);
  75.                 if ((sW = s.width) && (cW = dE.clientWidth))
  76.                         return calc(sW, cW);
  77.                 return false; // no match, so cannot - or don't need to - track zoom
  78.  
  79.                 function calc (x,y) { return (parseInt(x,10) / parseInt(y,10) * 100).toFixed(); }
  80.         }
  81.  
  82. };
  83. // add initialization method to Layout's onLoad array of functions
  84. _.onReady.push( $.layout.browserZoom._init );
  85.  
  86. })( jQuery );