1!function(root, name, make) { 2 if (typeof module != 'undefined' && module['exports']) module['exports'] = make(); 3 else root[name] = make(); 4}(this, 'verge', function() { 5 6 var xports = {} 7 , win = typeof window != 'undefined' && window 8 , doc = typeof document != 'undefined' && document 9 , docElem = doc && doc.documentElement 10 , matchMedia = win['matchMedia'] || win['msMatchMedia'] 11 , mq = matchMedia ? function(q) { 12 return !!matchMedia.call(win, q).matches; 13 } : function() { 14 return false; 15 } 16 , viewportW = xports['viewportW'] = function() { 17 var a = docElem['clientWidth'], b = win['innerWidth']; 18 return a < b ? b : a; 19 } 20 , viewportH = xports['viewportH'] = function() { 21 var a = docElem['clientHeight'], b = win['innerHeight']; 22 return a < b ? b : a; 23 }; 24 25 /** 26 * Test if a media query is active. Like Modernizr.mq 27 * @since 1.6.0 28 * @return {boolean} 29 */ 30 xports['mq'] = mq; 31 32 /** 33 * Normalized matchMedia 34 * @since 1.6.0 35 * @return {MediaQueryList|Object} 36 */ 37 xports['matchMedia'] = matchMedia ? function() { 38 // matchMedia must be binded to window 39 return matchMedia.apply(win, arguments); 40 } : function() { 41 // Gracefully degrade to plain object 42 return {}; 43 }; 44 45 /** 46 * @since 1.8.0 47 * @return {{width:number, height:number}} 48 */ 49 function viewport() { 50 return {'width':viewportW(), 'height':viewportH()}; 51 } 52 xports['viewport'] = viewport; 53 54 /** 55 * Cross-browser window.scrollX 56 * @since 1.0.0 57 * @return {number} 58 */ 59 xports['scrollX'] = function() { 60 return win.pageXOffset || docElem.scrollLeft; 61 }; 62 63 /** 64 * Cross-browser window.scrollY 65 * @since 1.0.0 66 * @return {number} 67 */ 68 xports['scrollY'] = function() { 69 return win.pageYOffset || docElem.scrollTop; 70 }; 71 72 /** 73 * @param {{top:number, right:number, bottom:number, left:number}} coords 74 * @param {number=} cushion adjustment 75 * @return {Object} 76 */ 77 function calibrate(coords, cushion) { 78 var o = {}; 79 cushion = +cushion || 0; 80 o['width'] = (o['right'] = coords['right'] + cushion) - (o['left'] = coords['left'] - cushion); 81 o['height'] = (o['bottom'] = coords['bottom'] + cushion) - (o['top'] = coords['top'] - cushion); 82 return o; 83 } 84 85 /** 86 * Cross-browser element.getBoundingClientRect plus optional cushion. 87 * Coords are relative to the top-left corner of the viewport. 88 * @since 1.0.0 89 * @param {Element|Object} el element or stack (uses first item) 90 * @param {number=} cushion +/- pixel adjustment amount 91 * @return {Object|boolean} 92 */ 93 function rectangle(el, cushion) { 94 el = el && !el.nodeType ? el[0] : el; 95 if (!el || 1 !== el.nodeType) return false; 96 return calibrate(el.getBoundingClientRect(), cushion); 97 } 98 xports['rectangle'] = rectangle; 99 100 /** 101 * Get the viewport aspect ratio (or the aspect ratio of an object or element) 102 * @since 1.7.0 103 * @param {(Element|Object)=} o optional object with width/height props or methods 104 * @return {number} 105 * @link http://w3.org/TR/css3-mediaqueries/#orientation 106 */ 107 function aspect(o) { 108 o = null == o ? viewport() : 1 === o.nodeType ? rectangle(o) : o; 109 var h = o['height'], w = o['width']; 110 h = typeof h == 'function' ? h.call(o) : h; 111 w = typeof w == 'function' ? w.call(o) : w; 112 return w/h; 113 } 114 xports['aspect'] = aspect; 115 116 /** 117 * Test if an element is in the same x-axis section as the viewport. 118 * @since 1.0.0 119 * @param {Element|Object} el 120 * @param {number=} cushion 121 * @return {boolean} 122 */ 123 xports['inX'] = function(el, cushion) { 124 var r = rectangle(el, cushion); 125 return !!r && r.right >= 0 && r.left <= viewportW(); 126 }; 127 128 /** 129 * Test if an element is in the same y-axis section as the viewport. 130 * @since 1.0.0 131 * @param {Element|Object} el 132 * @param {number=} cushion 133 * @return {boolean} 134 */ 135 xports['inY'] = function(el, cushion) { 136 var r = rectangle(el, cushion); 137 return !!r && r.bottom >= 0 && r.top <= viewportH(); 138 }; 139 140 /** 141 * Test if an element is in the viewport. 142 * @since 1.0.0
143 * @param {Element|Object} el 144 * @param {number=} cushion 145 * @return {boolean} 146 */ 147 xports['inViewport'] = function(el, cushion) { 148 // Equiv to `inX(el, cushion) && inY(el, cushion)` but just manually do both 149 // to avoid calling rectangle() twice. It gzips just as small like this. 150 var r = rectangle(el, cushion); 151 return !!r && r.bottom >= 0 && r.right >= 0 && r.top <= viewportH() && r.left <= viewportW(); 152 }; 153 154 return xports; 155});
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.