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