!function(t){"undefined"!=typeof define&&define.amd?define([],t):"undefined"!=typeof module&&module.exports?module.exports=t():t()}(function(){function t(){if(r.viewportTop=l(),r.viewportBottom=r.viewportTop+r.viewportHeight,r.documentHeight=y(),r.documentHeight!==I){for(H=a.length;H--;)a[H].recalculateLocation();I=r.documentHeight}}function i(){r.viewportHeight=V(),t(),e()}function o(){clearTimeout(E),E=setTimeout(i,100)}function e(){for(T=a.length;T--;)a[T].update();for(T=a.length;T--;)a[T].triggerCallbacks()}function s(t,i){function o(t){if(0!==t.length)for(V=t.length;V--;)y=t[V],y.callback.call(e,k),y.isOne&&t.splice(V,1)}var e=this;this.watchItem=t,i?i===+i?this.offsets={top:i,bottom:i}:this.offsets={top:i.top||g.top,bottom:i.bottom||g.bottom}:this.offsets=g,this.callbacks={};for(var s=0,n=v.length;s0?this.top=this.bottom=this.watchItem:this.top=this.bottom=r.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===t&&void 0===i||this.top===t&&this.bottom===i||o(this.callbacks[d])}},this.recalculateLocation(),this.update(),h=this.isInViewport,c=this.isFullyInViewport,l=this.isAboveViewport,a=this.isBelowViewport}function n(i){k=i,t(),e()}var h="undefined"==typeof window,c=!h,l=function(){return h?0:window.pageYOffset||document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop},r={},a=[],p="visibilityChange",w="enterViewport",u="fullyEnterViewport",f="exitViewport",m="partiallyExitViewport",d="locationChange",b="stateChange",v=[p,w,u,f,m,d,b],g={top:0,bottom:0},V=function(){return h?0:window.innerHeight||document.documentElement.clientHeight},y=function(){return h?0:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.documentElement.clientHeight)};r.viewportTop=null,r.viewportBottom=null,r.documentHeight=null,r.viewportHeight=V();var I,k,H,E,T;s.prototype={on:function(t,i,o){switch(!0){case t===p&&!this.isInViewport&&this.isAboveViewport:case t===w&&this.isInViewport:case t===u&&this.isFullyInViewport:case t===f&&this.isAboveViewport&&!this.isInViewport:case t===m&&this.isAboveViewport:if(i.call(this,k),o)return}if(!this.callbacks[t])throw new Error("Tried to add a scroll monitor listener of type "+t+". Your options are: "+v.join(", "));this.callbacks[t].push({callback:i,isOne:o||!1})},off:function(t,i){if(!this.callbacks[t])throw new Error("Tried to remove a scroll monitor listener of type "+t+". Your options are: "+v.join(", "));for(var o,e=0;o=this.callbacks[t][e];e++)if(o.callback===i){this.callbacks[t].splice(e,1);break}},one:function(t,i){this.on(t,i,!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.topr.viewportBottom,this.isInViewport=this.topr.viewportTop,this.isFullyInViewport=this.top>=r.viewportTop&&this.bottom<=r.viewportBottom||this.isAboveViewport&&this.isBelowViewport},destroy:function(){var t=a.indexOf(this),i=this;a.splice(t,1);for(var o=0,e=v.length;o, you must use jQuery.")}}return c&&(window.addEventListener?(window.addEventListener("scroll",n),window.addEventListener("resize",o)):(window.attachEvent("onscroll",n),window.attachEvent("onresize",o))),r.beget=r.create=function(t,i){"string"==typeof t?t=document.querySelector(t):t&&t.length>0&&(t=t[0]);var o=new s(t,i);return a.push(o),o.update(),o},r.update=function(){k=null,t(),e()},r.recalculateLocations=function(){r.documentHeight=0,r.update()},r.eventTypes=v,c&&(window.scrollMonitor=r),r});