Build 576754stable
Module 899898
6,736 characters · in 68925.4de164704c201108.jsDependencies
Source Raw
function(){!function(e,t){"use strict";if("IntersectionObserver"in e&&"IntersectionObserverEntry"in e&&"intersectionRatio"in e.IntersectionObserverEntry.prototype){"isIntersecting"in e.IntersectionObserverEntry.prototype||Object.defineProperty(e.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});return}var r=[];function n(e){this.time=e.time,this.target=e.target,this.rootBounds=e.rootBounds,this.boundingClientRect=e.boundingClientRect,this.intersectionRect=e.intersectionRect||l(),this.isIntersecting=!!e.intersectionRect;var t=this.boundingClientRect,r=t.width*t.height,n=this.intersectionRect,i=n.width*n.height;r?this.intersectionRatio=i/r:this.intersectionRatio=+!!this.isIntersecting}function i(e,t){var r,n,i,o=t||{};if("function"!=typeof e)throw Error("callback must be a function");if(o.root&&1!=o.root.nodeType)throw Error("root must be an Element");this._checkForIntersections=(r=this._checkForIntersections.bind(this),n=this.THROTTLE_TIMEOUT,i=null,function(){i||(i=setTimeout(function(){r(),i=null},n))}),this._callback=e,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(o.rootMargin),this.thresholds=this._initThresholds(o.threshold),this.root=o.root||null,this.rootMargin=this._rootMarginValues.map(function(e){return e.value+e.unit}).join(" ")}function o(e,t,r,n){"function"==typeof e.addEventListener?e.addEventListener(t,r,n||!1):"function"==typeof e.attachEvent&&e.attachEvent("on"+t,r)}function a(e,t,r,n){"function"==typeof e.removeEventListener?e.removeEventListener(t,r,n||!1):"function"==typeof e.detatchEvent&&e.detatchEvent("on"+t,r)}function s(e){var t;try{t=e.getBoundingClientRect()}catch(e){}return t?(t.width&&t.height||(t={top:t.top,right:t.right,bottom:t.bottom,left:t.left,width:t.right-t.left,height:t.bottom-t.top}),t):l()}function l(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function u(e,t){for(var r=t;r;){if(r==e)return!0;r=c(r)}return!1}function c(e){var t=e.parentNode;return t&&11==t.nodeType&&t.host?t.host:t}i.prototype.THROTTLE_TIMEOUT=100,i.prototype.POLL_INTERVAL=null,i.prototype.USE_MUTATION_OBSERVER=!0,i.prototype.observe=function(e){if(!this._observationTargets.some(function(t){return t.element==e})){if(!(e&&1==e.nodeType))throw Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:e,entry:null}),this._monitorIntersections(),this._checkForIntersections()}},i.prototype.unobserve=function(e){this._observationTargets=this._observationTargets.filter(function(t){return t.element!=e}),this._observationTargets.length||(this._unmonitorIntersections(),this._unregisterInstance())},i.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorIntersections(),this._unregisterInstance()},i.prototype.takeRecords=function(){var e=this._queuedEntries.slice();return this._queuedEntries=[],e},i.prototype._initThresholds=function(e){var t=e||[0];return Array.isArray(t)||(t=[t]),t.sort().filter(function(e,t,r){if("number"!=typeof e||isNaN(e)||e<0||e>1)throw Error("threshold must be a number between 0 and 1 inclusively");return e!==r[t-1]})},i.prototype._parseRootMargin=function(e){var t=(e||"0px").split(/\s+/).map(function(e){var t=/^(-?\d*\.?\d+)(px|%)$/.exec(e);if(!t)throw Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(t[1]),unit:t[2]}});return t[1]=t[1]||t[0],t[2]=t[2]||t[0],t[3]=t[3]||t[1],t},i.prototype._monitorIntersections=function(){!this._monitoringIntersections&&(this._monitoringIntersections=!0,this.POLL_INTERVAL?this._monitoringInterval=setInterval(this._checkForIntersections,this.POLL_INTERVAL):(o(e,"resize",this._checkForIntersections,!0),o(t,"scroll",this._checkForIntersections,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in e&&(this._domObserver=new MutationObserver(this._checkForIntersections),this._domObserver.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))))},i.prototype._unmonitorIntersections=function(){this._monitoringIntersections&&(this._monitoringIntersections=!1,clearInterval(this._monitoringInterval),this._monitoringInterval=null,a(e,"resize",this._checkForIntersections,!0),a(t,"scroll",this._checkForIntersections,!0),this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null))},i.prototype._checkForIntersections=function(){var t=this._rootIsInDom(),r=t?this._getRootRect():l();this._observationTargets.forEach(function(i){var o=i.element,a=s(o),l=this._rootContainsTarget(o),u=i.entry,c=t&&l&&this._computeTargetAndRootIntersection(o,r),f=i.entry=new n({time:e.performance&&performance.now&&performance.now(),target:o,boundingClientRect:a,rootBounds:r,intersectionRect:c});u?t&&l?this._hasCrossedThreshold(u,f)&&this._queuedEntries.push(f):u&&u.isIntersecting&&this._queuedEntries.push(f):this._queuedEntries.push(f)},this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)},i.prototype._computeTargetAndRootIntersection=function(r,n){if("none"!=e.getComputedStyle(r).display){for(var i=s(r),o=c(r),a=!1;!a;){var l=null,u=1==o.nodeType?e.getComputedStyle(o):{};if("none"==u.display)return;if(o==this.root||o==t?(a=!0,l=n):o!=t.body&&o!=t.documentElement&&"visible"!=u.overflow&&(l=s(o)),l&&!(i=function(e,t){var r=Math.max(e.top,t.top),n=Math.min(e.bottom,t.bottom),i=Math.max(e.left,t.left),o=Math.min(e.right,t.right),a=o-i,s=n-r;return a>=0&&s>=0&&{top:r,bottom:n,left:i,right:o,width:a,height:s}}(l,i)))break;o=c(o)}return i}},i.prototype._getRootRect=function(){var e;if(this.root)e=s(this.root);else{var r=t.documentElement,n=t.body;e={top:0,left:0,right:r.clientWidth||n.clientWidth,width:r.clientWidth||n.clientWidth,bottom:r.clientHeight||n.clientHeight,height:r.clientHeight||n.clientHeight}}return this._expandRectByRootMargin(e)},i.prototype._expandRectByRootMargin=function(e){var t=this._rootMarginValues.map(function(t,r){return"px"==t.unit?t.value:t.value*(r%2?e.width:e.height)/100}),r={top:e.top-t[0],right:e.right+t[1],bottom:e.bottom+t[2],left:e.left-t[3]};return r.width=r.right-r.left,r.height=r.bottom-r.top,r},i.prototype._hasCrossedThreshold=function(e,t){var r=e&&e.isIntersecting?e.intersectionRatio||0:-1,n=t.isIntersecting?t.intersectionRatio||0:-1;if(r!==n)for(var i=0;i<this.thresholds.length;i++){var o=this.thresholds[i];if(o==r||o==n||o<r!=o<n)return!0}},i.prototype._rootIsInDom=function(){return!this.root||u(t,this.root)},i.prototype._rootContainsTarget=function(e){return u(this.root||t,e)},i.prototype._registerInstance=function(){0>r.indexOf(this)&&r.push(this)},i.prototype._unregisterInstance=function(){var e=r.indexOf(this);-1!=e&&r.splice(e,1)},e.IntersectionObserver=i,e.IntersectionObserverEntry=n}(window,document)}