forked from expandtheroom/jquery-infinite-scroll-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.infinite-scroll-helper.min.js
1 lines (1 loc) · 3.08 KB
/
jquery.infinite-scroll-helper.min.js
1
!function(a,b){"use strict";function c(c,d){this.options=a.extend({},h,d),this.$element=a(c),this.$win=a(b),this.$loadingClassTarget=this._getLoadingClassTarget(),this.$scrollContainer=this._getScrollContainer(),this.loading=!1,this.doneLoadingInt=null,this.pageCount=this.options.triggerInitialLoad?this.options.startingPageCount-1:this.options.startingPageCount,this.destroyed=!1,this._init()}function d(b,c,d){b&&a.isFunction(b[c])&&b[c].apply(b,d)}function e(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}var f="infiniteScrollHelper",g="plugin_"+f,h={bottomBuffer:0,debounceInt:100,doneLoading:null,interval:300,loadingClass:"loading",loadingClassTarget:null,loadMoreDelay:0,loadMore:a.noop,startingPageCount:1,triggerInitialLoad:!1};c.prototype._init=function(){this._addListeners(),this.options.triggerInitialLoad?this._beginLoadMore(this.options.loadMoreDelay):this._handleScroll()},c.prototype._getLoadingClassTarget=function(){return this.options.loadingClassTarget?a(this.options.loadingClassTarget):this.$element},c.prototype._getScrollContainer=function(){var b=null;return"scroll"==this.$element.css("overflow-y")&&(b=this.$element),b||(b=this.$element.parents().filter(function(){return"scroll"==a(this).css("overflow-y")})),b=b.length>0?b:this.$win},c.prototype._addListeners=function(){var a=this;this.$scrollContainer.on("scroll."+f,e(function(){a._handleScroll()},this.options.debounceInt))},c.prototype._removeListeners=function(){this.$scrollContainer.off("scroll."+f)},c.prototype._handleScroll=function(){var a=this;this._shouldTriggerLoad()&&(this._beginLoadMore(this.options.loadMoreDelay),this.options.doneLoading&&(this.doneLoadingInt=setInterval(function(){a.options.doneLoading(a.pageCount)&&a._endLoadMore()},this.options.interval)))},c.prototype._shouldTriggerLoad=function(){var a=this._getElementHeight(),b=this.$scrollContainer.scrollTop()+this.$scrollContainer.height()+this.options.bottomBuffer;return!this.loading&&b>=a&&this.$element.is(":visible")},c.prototype._getElementHeight=function(){return this.$element==this.$scrollContainer?this.$element[0].scrollHeight:this.$element.height()},c.prototype._beginLoadMore=function(b){b=b||0,setTimeout(a.proxy(function(){this.pageCount++,this.options.loadMore(this.pageCount,a.proxy(this._endLoadMore,this)),this.$loadingClassTarget.addClass(this.options.loadingClass)},this),b),this.loading=!0,this._removeListeners()},c.prototype._endLoadMore=function(){clearInterval(this.doneLoadingInt),this.loading=!1,this.$loadingClassTarget.removeClass(this.options.loadingClass),!this.destroyed&&this._addListeners()},c.prototype.destroy=function(){this._removeListeners(),this.options.loadMore=null,this.options.doneLoading=null,a.data(this.$element[0],g,null),clearInterval(this.doneLoadingInt),this.destroyed=!0},a.fn[f]=function(b){var e=!1,f=arguments;return"string"==typeof b&&(e=b),this.each(function(){var h=a.data(this,g);h||e?e&&d(h,e,Array.prototype.slice.call(f,1)):a.data(this,g,new c(this,b))})},b.InfiniteScrollHelper=b.InfiniteScrollHelper||c}(jQuery,window);