-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-scroll-listener.min.js
1 lines (1 loc) · 3.43 KB
/
react-scroll-listener.min.js
1
"use strict";function _classCallCheck(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(r,e){for(var t=0;t<e.length;t++){var l=e[t];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(r,l.key,l)}}function _createClass(r,e,t){return e&&_defineProperties(r.prototype,e),t&&_defineProperties(r,t),Object.defineProperty(r,"prototype",{writable:!1}),r}(function(){var r,e,t,l,n,o;n=require("types.js"),o=require("uuid"),r=function(){var r,e=function(){function e(t){_classCallCheck(this,e),this._onHostScrollEnd=this._onHostScrollEnd.bind(this),this._onHostScroll=this._onHostScroll.bind(this),t=n.forceObject(t),this.scrollHost=n.forceObject(t.host),this.scrollStartHandlers={},this.scrollEndHandlers={},this.scrollTop=0,this.isScrolling=!1,this.scrollTimeoutDelay=n.forceNumber(t.delay,r),this._scrollTimeout=void 0,this.scrollListenerSet=!1}return _createClass(e,[{key:"addScrollEventListener",value:function(){if(!this.scrollListenerSet){if(!this.scrollHost.addEventListener){if("undefined"==typeof window)return console.log("ScrollListener::addScrollEventListener -> bad or missing host/window, cannot add event-listener!");this.scrollHost=window}return this.scrollHost.addEventListener("scroll",this._onHostScroll),this.scrollListenerSet=!0}}},{key:"removeScrollEventListener",value:function(){return this.scrollHost.removeEventListener("scroll",this._onHostScroll)}},{key:"addScrollHandler",value:function(r,e,t){return(r=n.forceString(r))?(e=n.forceFunction(e),t&&!this.scrollEndHandlers[r]?this.scrollEndHandlers[r]=e:this.scrollStartHandlers[r]||(this.scrollStartHandlers[r]=e),this.addScrollEventListener()):console.log("ScrollListener::addScrollHandler -> cannot add handler without id!")}},{key:"addScrollStartHandler",value:function(r,e){return this.addScrollHandler(r,e)}},{key:"addScrollEndHandler",value:function(r,e){return this.addScrollHandler(r,e,!0)}},{key:"removeScrollStartHandler",value:function(r){return delete this.scrollStartHandlers[r]}},{key:"removeScrollEndHandler",value:function(r){return delete this.scrollEndHandlers[r]}},{key:"removeScrollHandlers",value:function(){return this.scrollStartHandlers={},this.scrollEndHandlers={}}},{key:"_onHostScrollEnd",value:function(r){var e,t;if(this.scrollTop===this.scrollHost.pageYOffset){for(e in clearTimeout(this._scrollTimeout),this.isScrolling=!1,t=[],this.scrollEndHandlers)t.push(this.scrollEndHandlers[e](r));return t}}},{key:"_onHostScroll",value:function(r){var e;for(e in this.isScrolling=!0,this.scrollTop=this.scrollHost.pageYOffset,clearTimeout(this._scrollTimeout),this.scrollStartHandlers)this.scrollStartHandlers[e](r);return this._scrollTimeout=setTimeout(this._onHostScrollEnd.bind(this,r),this.scrollTimeoutDelay)}}]),e}();return r=300,e}.call(this),t={},l=function(e){return t[e]||(t[e]=new r)},e=function(r){var e,t;return t=o.v4(),e=o.v4(),{scrollListener:l(n.forceString(r,"generic")),componentDidMount:function(){return this.scrollListener.addScrollStartHandler(t,this.onScrollStart),this.scrollListener.addScrollEndHandler(e,this.onScrollEnd)},componentWillUnmount:function(){return this.scrollListener.removeScrollStartHandler(t),this.scrollListener.removeScrollEndHandler(e)}}},r.componentWillMount=function(){throw new Error("You are trying to use ScrollListenerMixin as an object, but it's a Function! Check the mixin for usage details.")},r.Mixin=e,r.ScrollListenerMixin=e,module.exports=r}).call(void 0);