-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelay-execution.min.js
1 lines (1 loc) · 2.25 KB
/
delay-execution.min.js
1
"use strict";function _classCallCheck(e,i){if(!(e instanceof i))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,i){for(var t=0;t<i.length;t++){var n=i[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,i,t){return i&&_defineProperties(e.prototype,i),t&&_defineProperties(e,t),e}var DelayExecution=function(){function v(e){var i=e.elem,t=void 0===i?null:i,n=e.func,o=void 0===n?null:n,s=e.direction,l=void 0===s?"v":s,r=e.parent,c=void 0===r?window:r,h=e.pixelDelay,a=void 0===h?0:h,u=e.timeDelay,d=void 0===u?0:u,f=e.includeElemHeight,m=void 0===f||f,w=e.debounce,p=void 0===w?500:w;if(_classCallCheck(this,v),!(t instanceof HTMLElement))throw new TypeError('"elem" is not HTMLElement');if(!(o instanceof Function))throw new TypeError('"func" is not Function');this.elem=t,this.func=o,this.direction=l,this.parent=c,this.pixelDelay=a,this.timeDelay=d,this.includeElemHeight=m,this.debounce=p,"Window"!==c.constructor.name&&"static"===getComputedStyle(c).getPropertyValue("position")&&(c.style.position="relative"),c.addEventListener("scroll",this.checkPosition.bind(this)),this.getElemPosition(),this.checkPosition(),c.addEventListener("resize",this.followWindowResizing.bind(this))}return _createClass(v,[{key:"getElemPosition",value:function(){this.elemPosition=("v"===this.direction?this.elem.offsetTop:this.elem.offsetLeft)+this.pixelDelay,this.includeElemHeight&&(this.elemPosition+=this.elem.offsetHeight)}},{key:"getParentPosition",value:function(){return"v"!==this.direction?"Window"===this.parent.constructor.name?window.innerWidth+window.scrollX:this.parent.clientWidth+this.parent.scrollLeft:"Window"===this.parent.constructor.name?window.innerHeight+window.scrollY:this.parent.clientHeight+this.parent.scrollTop}},{key:"checkPosition",value:function(){this.getParentPosition()>=this.elemPosition&&(this.parent.removeEventListener("scroll",this.checkPosition.bind(this)),this.parent.removeEventListener("resize",this.followWindowResizing.bind(this)),setTimeout(this.func,this.timeDelay))}},{key:"followWindowResizing",value:function(){clearTimeout(this.followWindowResizingTimeout),this.followWindowResizingTimeout=setTimeout(this.getElemPosition,this.debounce)}}]),v}();