!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("scrollMonitor",[],t):"object"==typeof exports?exports.scrollMonitor=t():n.scrollMonitor=t()}(this,function(){return function(n){function t(r){if(i[r])return i[r].exports;var u=i[r]={exports:{},id:r,loaded:!1};return n[r].call(u.exports,u,u.exports,t),u.loaded=!0,u.exports}var i={};return t.m=n,t.c=i,t.p="",t(0)}([function(n,t,i){"use strict";var f=i(1),u=f.isInBrowser,e=i(2),r=new e(u?document.body:null);r.setStateFromDOM(null);r.listenToDOM();u&&(window.scrollMonitor=r);n.exports=r},function(n,t){"use strict";t.VISIBILITYCHANGE="visibilityChange";t.ENTERVIEWPORT="enterViewport";t.FULLYENTERVIEWPORT="fullyEnterViewport";t.EXITVIEWPORT="exitViewport";t.PARTIALLYEXITVIEWPORT="partiallyExitViewport";t.LOCATIONCHANGE="locationChange";t.STATECHANGE="stateChange";t.eventTypes=[t.VISIBILITYCHANGE,t.ENTERVIEWPORT,t.FULLYENTERVIEWPORT,t.EXITVIEWPORT,t.PARTIALLYEXITVIEWPORT,t.LOCATIONCHANGE,t.STATECHANGE];t.isOnServer="undefined"==typeof window;t.isInBrowser=!t.isOnServer;t.defaultOffsets={top:0,bottom:0}},function(n,t,i){"use strict";function s(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function");}function e(n){return f?0:n===document.body?window.innerHeight||document.documentElement.clientHeight:n.clientHeight}function r(n){return f?0:n===document.body?Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.documentElement.clientHeight):n.scrollHeight}function o(n){return f?0:n===document.body?window.pageYOffset||document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop:n.scrollTop}var u=i(1),f=u.isOnServer,h=u.isInBrowser,c=u.eventTypes,l=i(3),a=function(){function n(t,i){function a(){if(u.viewportTop=o(t),u.viewportBottom=u.viewportTop+u.viewportHeight,u.documentHeight=r(t),u.documentHeight!==l){for(h=u.watchers.length;h--;)u.watchers[h].recalculateLocation();l=u.documentHeight}}function v(){for(f=u.watchers.length;f--;)u.watchers[f].update();for(f=u.watchers.length;f--;)u.watchers[f].triggerCallbacks()}var u,l,h,f;s(this,n);u=this;this.item=t;this.watchers=[];this.viewportTop=null;this.viewportBottom=null;this.documentHeight=r(t);this.viewportHeight=e(t);this.DOMListener=function(){n.prototype.DOMListener.apply(u,arguments)};this.eventTypes=c;i&&(this.containerWatcher=i.create(t));this.update=function(){a();v()};this.recalculateLocations=function(){this.documentHeight=0;this.update()}}return n.prototype.listenToDOM=function(){h&&(window.addEventListener?(this.item===document.body?window.addEventListener("scroll",this.DOMListener):this.item.addEventListener("scroll",this.DOMListener),window.addEventListener("resize",this.DOMListener)):(this.item===document.body?window.attachEvent("onscroll",this.DOMListener):this.item.attachEvent("onscroll",this.DOMListener),window.attachEvent("onresize",this.DOMListener)),this.destroy=function(){window.addEventListener?(this.item===document.body?(window.removeEventListener("scroll",this.DOMListener),this.containerWatcher.destroy()):this.item.removeEventListener("scroll",this.DOMListener),window.removeEventListener("resize",this.DOMListener)):(this.item===document.body?(window.detachEvent("onscroll",this.DOMListener),this.containerWatcher.destroy()):this.item.detachEvent("onscroll",this.DOMListener),window.detachEvent("onresize",this.DOMListener))})},n.prototype.destroy=function(){},n.prototype.DOMListener=function(n){this.setStateFromDOM(n);this.updateAndTriggerWatchers(n)},n.prototype.setStateFromDOM=function(n){var t=o(this.item),i=e(this.item),u=r(this.item);this.setState(t,i,u,n)},n.prototype.setState=function(n,t,i,r){var f=t!==this.viewportHeight||i!==this.contentHeight,u;if(this.latestEvent=r,this.viewportTop=n,this.viewportHeight=t,this.viewportBottom=n+t,this.contentHeight=i,f)for(u=this.watchers.length;u--;)this.watchers[u].recalculateLocation();this.updateAndTriggerWatchers(r)},n.prototype.updateAndTriggerWatchers=function(n){for(var t=this.watchers.length;t--;)this.watchers[t].update();for(t=this.watchers.length;t--;)this.watchers[t].triggerCallbacks(n)},n.prototype.createCustomContainer=function(){return new n},n.prototype.createContainer=function(t){"string"==typeof t?t=document.querySelector(t):t&&t.length>0&&(t=t[0]);var i=new n(t,this);return i.setStateFromDOM(),i.listenToDOM(),i},n.prototype.create=function(n,t){"string"==typeof n?n=document.querySelector(n):n&&n.length>0&&(n=n[0]);var i=new l(this,n,t);return this.watchers.push(i),i},n.prototype.beget=function(n,t){return this.create(n,t)},n}();n.exports=a},function(n,t,i){"use strict";function f(n,t,i){function r(n,t){if(0!==n.length)for(k=n.length;k--;)g=n[k],g.callback.call(d,t,d),g.isOne&&n.splice(k,1)}var d=this,v,nt,f,a,w,b,k,g;for(this.watchItem=t,this.container=n,this.offsets=i?i===+i?{top:i,bottom:i}:{top:i.top||l.top,bottom:i.bottom||l.bottom}:l,this.callbacks={},v=0,nt=u.length;v<nt;v++)d.callbacks[u[v]]=[];this.locked=!1;this.triggerCallbacks=function(n){switch(this.isInViewport&&!f&&r(this.callbacks[o],n),this.isFullyInViewport&&!a&&r(this.callbacks[s],n),this.isAboveViewport!==w&&this.isBelowViewport!==b&&(r(this.callbacks[e],n),a||this.isFullyInViewport||(r(this.callbacks[s],n),r(this.callbacks[c],n)),f||this.isInViewport||(r(this.callbacks[o],n),r(this.callbacks[h],n))),!this.isFullyInViewport&&a&&r(this.callbacks[c],n),!this.isInViewport&&f&&r(this.callbacks[h],n),this.isInViewport!==f&&r(this.callbacks[e],n),!0){case f!==this.isInViewport:case a!==this.isFullyInViewport:case w!==this.isAboveViewport:case b!==this.isBelowViewport:r(this.callbacks[p],n)}f=this.isInViewport;a=this.isFullyInViewport;w=this.isAboveViewport;b=this.isBelowViewport};this.recalculateLocation=function(){var u,f,t,i,n,e;if(!this.locked){if(u=this.top,f=this.bottom,this.watchItem.nodeName){for(t=this.watchItem.style.display,"none"===t&&(this.watchItem.style.display=""),i=0,n=this.container;n.containerWatcher;)i+=n.containerWatcher.top-n.containerWatcher.container.viewportTop,n=n.containerWatcher.container;e=this.watchItem.getBoundingClientRect();this.top=e.top+this.container.viewportTop-i;this.bottom=e.bottom+this.container.viewportTop-i;"none"===t&&(this.watchItem.style.display=t)}else this.watchItem===+this.watchItem?this.top=this.watchItem>0?this.bottom=this.watchItem:this.bottom=this.container.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===u&&void 0===f||this.top===u&&this.bottom===f||r(this.callbacks[y],null)}};this.recalculateLocation();this.update();f=this.isInViewport;a=this.isFullyInViewport;w=this.isAboveViewport;b=this.isBelowViewport}var r=i(1),e=r.VISIBILITYCHANGE,o=r.ENTERVIEWPORT,s=r.FULLYENTERVIEWPORT,h=r.EXITVIEWPORT,c=r.PARTIALLYEXITVIEWPORT,y=r.LOCATIONCHANGE,p=r.STATECHANGE,u=r.eventTypes,l=r.defaultOffsets,v;f.prototype={on:function(n,t,i){switch(!0){case n===e&&!this.isInViewport&&this.isAboveViewport:case n===o&&this.isInViewport:case n===s&&this.isFullyInViewport:case n===h&&this.isAboveViewport&&!this.isInViewport:case n===c&&this.isAboveViewport:if(t.call(this,this.container.latestEvent,this),i)return}if(!this.callbacks[n])throw new Error("Tried to add a scroll monitor listener of type "+n+". Your options are: "+u.join(", "));this.callbacks[n].push({callback:t,isOne:i||!1})},off:function(n,t){if(!this.callbacks[n])throw new Error("Tried to remove a scroll monitor listener of type "+n+". Your options are: "+u.join(", "));for(var r,i=0;r=this.callbacks[n][i];i++)if(r.callback===t){this.callbacks[n].splice(i,1);break}},one:function(n,t){this.on(n,t,!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<this.container.viewportTop;this.isBelowViewport=this.bottom>this.container.viewportBottom;this.isInViewport=this.top<this.container.viewportBottom&&this.bottom>this.container.viewportTop;this.isFullyInViewport=this.top>=this.container.viewportTop&&this.bottom<=this.container.viewportBottom||this.isAboveViewport&&this.isBelowViewport},destroy:function(){var i=this.container.watchers.indexOf(this),r=this,n,t;for(this.container.watchers.splice(i,1),n=0,t=u.length;n<t;n++)r.callbacks[u[n]].length=0},lock:function(){this.locked=!0},unlock:function(){this.locked=!1}};for(var w=function(n){return function(t,i){this.on.call(this,n,t,i)}},a=0,b=u.length;a<b;a++)v=u[a],f.prototype[v]=w(v);n.exports=f}])})