forked from cmdjs/gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrollmonitor.js
More file actions
1 lines (1 loc) · 4.59 KB
/
scrollmonitor.js
File metadata and controls
1 lines (1 loc) · 4.59 KB
1
define("gallery/scrollmonitor/1.0.7/scrollmonitor",["jquery"],function(a,b,c){!function(b){if("undefined"!=typeof define&&define.amd)define(["jquery"],b);else if("undefined"!=typeof c&&c.exports){var d=a("jquery");c.exports=b(d)}else window.scrollMonitor=b(jQuery)}(function(a){function b(){return window.innerHeight||document.documentElement.clientHeight}function c(){if(i.viewportTop=j.scrollTop(),i.viewportBottom=i.viewportTop+i.viewportHeight,i.documentHeight=k.height(),i.documentHeight!==v){for(x=l.length;x--;)l[x].recalculateLocation();v=i.documentHeight}}function d(){i.viewportHeight=b(),c(),f()}function e(){clearTimeout(y),y=setTimeout(d,100)}function f(){for(z=l.length;z--;)l[z].update();for(z=l.length;z--;)l[z].triggerCallbacks()}function g(b,c){function d(a){if(0!==a.length)for(v=a.length;v--;)x=a[v],x.callback.call(e,w),x.isOne&&a.splice(v,1)}var e=this;this.watchItem=b,this.offsets=c?c===+c?{top:c,bottom:c}:a.extend({},u,c):u,this.callbacks={};for(var f=0,g=t.length;g>f;f++)e.callbacks[t[f]]=[];this.locked=!1;var h,j,k,l,v,x;this.triggerCallbacks=function(){switch(this.isInViewport&&!h&&d(this.callbacks[n]),this.isFullyInViewport&&!j&&d(this.callbacks[o]),this.isAboveViewport!==k&&this.isBelowViewport!==l&&(d(this.callbacks[m]),j||this.isFullyInViewport||(d(this.callbacks[o]),d(this.callbacks[q])),h||this.isInViewport||(d(this.callbacks[n]),d(this.callbacks[p]))),!this.isFullyInViewport&&j&&d(this.callbacks[q]),!this.isInViewport&&h&&d(this.callbacks[p]),this.isInViewport!==h&&d(this.callbacks[m]),!0){case h!==this.isInViewport:case j!==this.isFullyInViewport:case k!==this.isAboveViewport:case l!==this.isBelowViewport:d(this.callbacks[s])}h=this.isInViewport,j=this.isFullyInViewport,k=this.isAboveViewport,l=this.isBelowViewport},this.recalculateLocation=function(){if(!this.locked){var b=this.top,c=this.bottom;if(this.watchItem.nodeName){var e=this.watchItem.style.display;"none"===e&&(this.watchItem.style.display="");var f=a(this.watchItem).offset();this.top=f.top,this.bottom=f.top+this.watchItem.offsetHeight,"none"===e&&(this.watchItem.style.display=e)}else this.watchItem===+this.watchItem?this.top=this.bottom=this.watchItem>0?this.watchItem:i.documentHeight-this.watchItem:(this.top=this.watchItem.top,this.bottom=this.watchItem.bottom);this.top-=this.offsets.top,this.bottom+=this.offsets.bottom,this.height=this.bottom-this.top,void 0===b&&void 0===c||this.top===b&&this.bottom===c||d(this.callbacks[r])}},this.recalculateLocation(),this.update(),h=this.isInViewport,j=this.isFullyInViewport,k=this.isAboveViewport,l=this.isBelowViewport}function h(a){w=a,c(),f()}var i={},j=a(window),k=a(document),l=[],m="visibilityChange",n="enterViewport",o="fullyEnterViewport",p="exitViewport",q="partiallyExitViewport",r="locationChange",s="stateChange",t=[m,n,o,p,q,r,s],u={top:0,bottom:0};i.viewportTop,i.viewportBottom,i.documentHeight,i.viewportHeight=b();var v,w,x,y,z;g.prototype={on:function(a,b,c){switch(!0){case a===m&&!this.isInViewport&&this.isAboveViewport:case a===n&&this.isInViewport:case a===o&&this.isFullyInViewport:case a===p&&this.isAboveViewport&&!this.isInViewport:case a===q&&this.isAboveViewport:if(b(),c)return}if(!this.callbacks[a])throw new Error("Tried to add a scroll monitor listener of type "+a+". Your options are: "+t.join(", "));this.callbacks[a].push({callback:b,isOne:c})},off:function(a,b){if(!this.callbacks[a])throw new Error("Tried to remove a scroll monitor listener of type "+a+". Your options are: "+t.join(", "));for(var c,d=0;c=this.callbacks[a][d];d++)if(c.callback===b){this.callbacks[a].splice(d,1);break}},one:function(a,b){this.on(a,b,!0)},recalculateSize:function(){this.height=this.watchItem.offsetHeight+this.offsets.top+this.offsets.bottom,this.bottom=this.top+this.height},update:function(){this.isAboveViewport=this.top<i.viewportTop,this.isBelowViewport=this.bottom>i.viewportBottom,this.isInViewport=this.top<=i.viewportBottom&&this.bottom>=i.viewportTop,this.isFullyInViewport=this.top>=i.viewportTop&&this.bottom<=i.viewportBottom||this.isAboveViewport&&this.isBelowViewport},destroy:function(){var a=l.indexOf(this),b=this;l.splice(a,1);for(var c=0,d=t.length;d>c;c++)b.callbacks[t[c]].length=0},lock:function(){this.locked=!0},unlock:function(){this.locked=!1}};for(var A=function(a){return function(b,c){this.on.call(this,a,b,c)}},B=0,C=t.length;C>B;B++){var D=t[B];g.prototype[D]=A(D)}try{c()}catch(E){a(c)}return j.on("scroll",h),j.on("resize",e),i.beget=i.create=function(b,c){"string"==typeof b&&(b=a(b)[0]),b instanceof a&&(b=b[0]);var d=new g(b,c);return l.push(d),d.update(),d},i.update=function(){w=null,c(),f()},i.recalculateLocations=function(){i.documentHeight=0,i.update()},i})});