1
1
/*!
2
- * Infinite Scroll PACKAGED v3.0.0
2
+ * Infinite Scroll PACKAGED v3.0.1
3
3
* Automatically add next page
4
4
*
5
5
* Licensed GPLv3 for open source use
@@ -656,6 +656,7 @@ proto.create = function() {
656
656
// bail if getPath not set
657
657
if ( ! this . getPath ) {
658
658
console . error ( 'Disabling InfiniteScroll' ) ;
659
+ return ;
659
660
}
660
661
this . updateGetAbsolutePath ( ) ;
661
662
this . log ( 'initialized' , [ this . element . className ] ) ;
@@ -984,6 +985,7 @@ InfiniteScroll.defaults.responseType = 'document';
984
985
InfiniteScroll . create . pageLoad = function ( ) {
985
986
this . canLoad = true ;
986
987
this . on ( 'scrollThreshold' , this . onScrollThresholdLoad ) ;
988
+ this . on ( 'append' , this . checkLastPage ) ;
987
989
if ( this . options . outlayer ) {
988
990
this . on ( 'append' , this . onAppendOutlayer ) ;
989
991
}
@@ -1041,7 +1043,6 @@ proto.appendNextPage = function( response, path ) {
1041
1043
this . appendItems ( items , fragment ) ;
1042
1044
this . isLoading = false ;
1043
1045
this . dispatchEvent ( 'append' , null , [ response , path , items ] ) ;
1044
- this . checkLastPage ( response , path ) ;
1045
1046
} . bind ( this ) ;
1046
1047
1047
1048
// TODO add hook for option to trigger appendReady
@@ -1176,6 +1177,8 @@ InfiniteScroll.create.prefill = function() {
1176
1177
this . updateScroller ( ) ;
1177
1178
this . isPrefilling = true ;
1178
1179
this . on ( 'append' , this . prefill ) ;
1180
+ this . once ( 'error' , this . stopPrefill ) ;
1181
+ this . once ( 'last' , this . stopPrefill ) ;
1179
1182
this . prefill ( ) ;
1180
1183
} ;
1181
1184
@@ -1186,7 +1189,7 @@ proto.prefill = function() {
1186
1189
this . log ( 'prefill' ) ;
1187
1190
this . loadNextPage ( ) ;
1188
1191
} else {
1189
- this . off ( 'append' , this . prefill ) ;
1192
+ this . stopPrefill ( ) ;
1190
1193
}
1191
1194
} ;
1192
1195
@@ -1199,6 +1202,11 @@ proto.getPrefillDistance = function() {
1199
1202
return this . windowHeight - this . element . clientHeight ;
1200
1203
} ;
1201
1204
1205
+ proto . stopPrefill = function ( ) {
1206
+ console . log ( 'stopping prefill' ) ;
1207
+ this . off ( 'append' , this . prefill ) ;
1208
+ } ;
1209
+
1202
1210
// -------------------------- request -------------------------- //
1203
1211
1204
1212
function request ( url , responseType , onLoad , onError ) {
@@ -1427,7 +1435,7 @@ proto.createHistoryAppend = function() {
1427
1435
this . scrollPageIndex = 0 ;
1428
1436
// events
1429
1437
this . scrollHistoryHandler = this . onScrollHistory . bind ( this ) ;
1430
- this . beforeunloadHandler = this . onBeforeunload . bind ( this ) ;
1438
+ this . unloadHandler = this . onUnload . bind ( this ) ;
1431
1439
this . scroller . addEventListener ( 'scroll' , this . scrollHistoryHandler ) ;
1432
1440
this . on ( 'append' , this . onAppendHistory ) ;
1433
1441
this . bindHistoryAppendEvents ( true ) ;
@@ -1436,14 +1444,15 @@ proto.createHistoryAppend = function() {
1436
1444
proto . bindHistoryAppendEvents = function ( isBind ) {
1437
1445
var addRemove = isBind ? 'addEventListener' : 'removeEventListener' ;
1438
1446
this . scroller [ addRemove ] ( 'scroll' , this . scrollHistoryHandler ) ;
1439
- window [ addRemove ] ( 'beforeunload ' , this . beforeunloadHandler ) ;
1447
+ window [ addRemove ] ( 'unload ' , this . unloadHandler ) ;
1440
1448
} ;
1441
1449
1442
1450
proto . createHistoryPageLoad = function ( ) {
1443
1451
this . on ( 'load' , this . onPageLoadHistory ) ;
1444
1452
} ;
1445
1453
1446
- InfiniteScroll . destroy . history = function ( ) {
1454
+ InfiniteScroll . destroy . history =
1455
+ proto . destroyHistory = function ( ) {
1447
1456
var isHistoryAppend = this . options . history && this . options . append ;
1448
1457
if ( isHistoryAppend ) {
1449
1458
this . bindHistoryAppendEvents ( false ) ;
@@ -1530,14 +1539,16 @@ proto.setHistory = function( title, path ) {
1530
1539
1531
1540
// scroll to top to prevent initial scroll-reset after page refresh
1532
1541
// http://stackoverflow.com/a/18633915/182183
1533
- proto . onBeforeunload = function ( ) {
1542
+ proto . onUnload = function ( ) {
1534
1543
var pageIndex = this . scrollPageIndex ;
1535
1544
if ( pageIndex === 0 ) {
1536
1545
return ;
1537
1546
}
1538
1547
// calculate where scroll position would be on refresh
1539
1548
var scrollPage = this . scrollPages [ pageIndex ] ;
1540
1549
var scrollY = window . pageYOffset - scrollPage . top + this . top ;
1550
+ // disable scroll event before setting scroll #679
1551
+ this . destroyHistory ( ) ;
1541
1552
scrollTo ( 0 , scrollY ) ;
1542
1553
} ;
1543
1554
@@ -1596,7 +1607,7 @@ InfiniteScroll.create.button = function() {
1596
1607
1597
1608
InfiniteScroll . destroy . button = function ( ) {
1598
1609
if ( this . button ) {
1599
- this . button . destory ( ) ;
1610
+ this . button . destroy ( ) ;
1600
1611
}
1601
1612
} ;
1602
1613
@@ -1751,7 +1762,7 @@ return InfiniteScroll;
1751
1762
} ) ) ;
1752
1763
1753
1764
/*!
1754
- * Infinite Scroll v3.0.0
1765
+ * Infinite Scroll v3.0.1
1755
1766
* Automatically add next page
1756
1767
*
1757
1768
* Licensed GPLv3 for open source use
0 commit comments