Repository navigation
Expand file tree
/
Copy pathpulltoload.min.js
More file actions
1 lines (1 loc) · 2.79 KB
/
Copy pathpulltoload.min.js
File metadata and controls
1 lines (1 loc) · 2.79 KB
1
!function(){function e(){this.__events={}}function t(t,n){e.call(this),t.self===t||"body"==document.querySelector(t).tagName.toLowerCase()?(i=!0,this.element=window,this.container=document.body):this.container=this.element="string"==typeof t?document.querySelector(t):t,this.options=o.extend({},this.constructor.defaultOptions,n),this.init()}var n="object"==typeof self&&self.self==self&&self||"object"==typeof global&&global.global==global&&global||this||{},o={extend:function(e){for(var t=1,n=arguments.length;t<n;t++)for(var o in arguments[t])arguments[t].hasOwnProperty(o)&&(e[o]=arguments[t][o]);return e},isValidListener:function(e){return"function"==typeof e||!(!e||"object"!=typeof e)&&o.isValidListener(e.listener)},indexOf:function(e,t){if(e.indexOf)return e.indexOf(t);for(var n=-1,o=0,i=e.length;o<i;o++)if(e[o]===t){n=o;break}return n}};e.prototype.on=function(e,t){if(e&&t){if(!o.isValidListener(t))throw new TypeError("listener must be a function");var n=this.__events,i=n[e]=n[e]||[],s="object"==typeof t;return-1===o.indexOf(i,t)&&i.push(s?t:{listener:t,once:!1}),this}},e.prototype.once=function(e,t){return this.on(e,{listener:t,once:!0})},e.prototype.off=function(e,t){var n=this.__events[e];if(n){for(var o,i=0,s=n.length;i<s;i++)if(n[i]&&n[i].listener===t){o=i;break}return void 0!==o&&n.splice(o,1,null),this}},e.prototype.emit=function(e,t){var n=this.__events[e];if(n){for(var o=0;o<n.length;o++){var i=n[o];i&&(i.listener.apply(this,t||[]),i.once&&this.off(e,i.listener))}return this}};var i=!1;t.VERSION="1.0.0",t.defaultOptions={threshold:100,loader:"#loader"};var s=t.prototype=new e;s.constructor=t,s.init=function(){this.setLoader(),this.onscroll(),this.bindEvent()},s.setLoader=function(){var e="string"==typeof this.options.loader?document.querySelector(this.options.loader):this.options.loader;e&&(e.style.display="none",this._loader=e)},s.bindEvent=function(){this.element.addEventListener("scroll",this)},s.handleEvent=function(e){var t="on"+e.type;this[t]&&this[t](e)};var r=!1;s.onscroll=function(){this.onscroll=i?function(){(window.pageYOffset||document.documentElement.scrollTop)+(window.innerHeight||document.documentElement.clientHeight)>document.documentElement.scrollHeight-this.options.threshold&&this.append()}:function(){this.element.scrollTop+this.element.clientHeight>this.element.scrollHeight-this.options.threshold&&this.append()}},s.append=function(){r||(r=!0,this._loader&&(this.element.self===this.element?document.body.append(this._loader):this.element.append(this._loader),this._loader.style.display="block"),this.emit("load",[this.reset.bind(this)]))},s.reset=function(){this._loader&&(this._loader.style.display="none"),r=!1},"undefined"==typeof exports||exports.nodeType?n.PullToLoad=t:("undefined"!=typeof module&&!module.nodeType&&module.exports&&(exports=module.exports=t),exports.PullToLoad=t)}();