11/*!
2- * Infinite Scroll PACKAGED v3.0.0
2+ * Infinite Scroll PACKAGED v3.0.1
33 * Automatically add next page
44 *
55 * Licensed GPLv3 for open source use
@@ -656,6 +656,7 @@ proto.create = function() {
656656 // bail if getPath not set
657657 if ( ! this . getPath ) {
658658 console . error ( 'Disabling InfiniteScroll' ) ;
659+ return ;
659660 }
660661 this . updateGetAbsolutePath ( ) ;
661662 this . log ( 'initialized' , [ this . element . className ] ) ;
@@ -984,6 +985,7 @@ InfiniteScroll.defaults.responseType = 'document';
984985InfiniteScroll . create . pageLoad = function ( ) {
985986 this . canLoad = true ;
986987 this . on ( 'scrollThreshold' , this . onScrollThresholdLoad ) ;
988+ this . on ( 'append' , this . checkLastPage ) ;
987989 if ( this . options . outlayer ) {
988990 this . on ( 'append' , this . onAppendOutlayer ) ;
989991 }
@@ -1041,7 +1043,6 @@ proto.appendNextPage = function( response, path ) {
10411043 this . appendItems ( items , fragment ) ;
10421044 this . isLoading = false ;
10431045 this . dispatchEvent ( 'append' , null , [ response , path , items ] ) ;
1044- this . checkLastPage ( response , path ) ;
10451046 } . bind ( this ) ;
10461047
10471048 // TODO add hook for option to trigger appendReady
@@ -1176,6 +1177,8 @@ InfiniteScroll.create.prefill = function() {
11761177 this . updateScroller ( ) ;
11771178 this . isPrefilling = true ;
11781179 this . on ( 'append' , this . prefill ) ;
1180+ this . once ( 'error' , this . stopPrefill ) ;
1181+ this . once ( 'last' , this . stopPrefill ) ;
11791182 this . prefill ( ) ;
11801183} ;
11811184
@@ -1186,7 +1189,7 @@ proto.prefill = function() {
11861189 this . log ( 'prefill' ) ;
11871190 this . loadNextPage ( ) ;
11881191 } else {
1189- this . off ( 'append' , this . prefill ) ;
1192+ this . stopPrefill ( ) ;
11901193 }
11911194} ;
11921195
@@ -1199,6 +1202,11 @@ proto.getPrefillDistance = function() {
11991202 return this . windowHeight - this . element . clientHeight ;
12001203} ;
12011204
1205+ proto . stopPrefill = function ( ) {
1206+ console . log ( 'stopping prefill' ) ;
1207+ this . off ( 'append' , this . prefill ) ;
1208+ } ;
1209+
12021210// -------------------------- request -------------------------- //
12031211
12041212function request ( url , responseType , onLoad , onError ) {
@@ -1427,7 +1435,7 @@ proto.createHistoryAppend = function() {
14271435 this . scrollPageIndex = 0 ;
14281436 // events
14291437 this . scrollHistoryHandler = this . onScrollHistory . bind ( this ) ;
1430- this . beforeunloadHandler = this . onBeforeunload . bind ( this ) ;
1438+ this . unloadHandler = this . onUnload . bind ( this ) ;
14311439 this . scroller . addEventListener ( 'scroll' , this . scrollHistoryHandler ) ;
14321440 this . on ( 'append' , this . onAppendHistory ) ;
14331441 this . bindHistoryAppendEvents ( true ) ;
@@ -1436,14 +1444,15 @@ proto.createHistoryAppend = function() {
14361444proto . bindHistoryAppendEvents = function ( isBind ) {
14371445 var addRemove = isBind ? 'addEventListener' : 'removeEventListener' ;
14381446 this . scroller [ addRemove ] ( 'scroll' , this . scrollHistoryHandler ) ;
1439- window [ addRemove ] ( 'beforeunload ' , this . beforeunloadHandler ) ;
1447+ window [ addRemove ] ( 'unload ' , this . unloadHandler ) ;
14401448} ;
14411449
14421450proto . createHistoryPageLoad = function ( ) {
14431451 this . on ( 'load' , this . onPageLoadHistory ) ;
14441452} ;
14451453
1446- InfiniteScroll . destroy . history = function ( ) {
1454+ InfiniteScroll . destroy . history =
1455+ proto . destroyHistory = function ( ) {
14471456 var isHistoryAppend = this . options . history && this . options . append ;
14481457 if ( isHistoryAppend ) {
14491458 this . bindHistoryAppendEvents ( false ) ;
@@ -1530,14 +1539,16 @@ proto.setHistory = function( title, path ) {
15301539
15311540// scroll to top to prevent initial scroll-reset after page refresh
15321541// http://stackoverflow.com/a/18633915/182183
1533- proto . onBeforeunload = function ( ) {
1542+ proto . onUnload = function ( ) {
15341543 var pageIndex = this . scrollPageIndex ;
15351544 if ( pageIndex === 0 ) {
15361545 return ;
15371546 }
15381547 // calculate where scroll position would be on refresh
15391548 var scrollPage = this . scrollPages [ pageIndex ] ;
15401549 var scrollY = window . pageYOffset - scrollPage . top + this . top ;
1550+ // disable scroll event before setting scroll #679
1551+ this . destroyHistory ( ) ;
15411552 scrollTo ( 0 , scrollY ) ;
15421553} ;
15431554
@@ -1596,7 +1607,7 @@ InfiniteScroll.create.button = function() {
15961607
15971608InfiniteScroll . destroy . button = function ( ) {
15981609 if ( this . button ) {
1599- this . button . destory ( ) ;
1610+ this . button . destroy ( ) ;
16001611 }
16011612} ;
16021613
@@ -1751,7 +1762,7 @@ return InfiniteScroll;
17511762} ) ) ;
17521763
17531764/*!
1754- * Infinite Scroll v3.0.0
1765+ * Infinite Scroll v3.0.1
17551766 * Automatically add next page
17561767 *
17571768 * Licensed GPLv3 for open source use
0 commit comments