UNPKG

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