1
1
/*!
2
- * Infinite Scroll PACKAGED v3.0.5
2
+ * Infinite Scroll PACKAGED v3.0.6
3
3
* Automatically add next page
4
4
*
5
5
* Licensed GPLv3 for open source use
@@ -797,9 +797,13 @@ proto.updateGetPathTemplate = function( optPath ) {
797
797
} . bind ( this ) ;
798
798
// get pageIndex from location
799
799
// convert path option into regex to look for pattern in location
800
- var regexString = optPath . replace ( '{{#}}' , '(\\d\\d?\\d?)' ) ;
800
+ // escape query (?) in url, allows for parsing GET parameters
801
+ var regexString = optPath
802
+ . replace ( / ( \\ \? | \? ) / , '\\?' )
803
+ . replace ( '{{#}}' , '(\\d\\d?\\d?)' ) ;
801
804
var templateRe = new RegExp ( regexString ) ;
802
805
var match = location . href . match ( templateRe ) ;
806
+
803
807
if ( match ) {
804
808
this . pageIndex = parseInt ( match [ 1 ] , 10 ) ;
805
809
this . log ( 'pageIndex' , [ this . pageIndex , 'template string' ] ) ;
@@ -859,9 +863,17 @@ proto.updateGetAbsolutePath = function() {
859
863
}
860
864
861
865
var pathname = location . pathname ;
866
+ // query parameter #829. example.com/?pg=2
867
+ var isQuery = path . match ( / ^ \? / ) ;
868
+ if ( isQuery ) {
869
+ this . getAbsolutePath = function ( ) {
870
+ return pathname + this . getPath ( ) ;
871
+ } ;
872
+ return ;
873
+ }
874
+
862
875
// /foo/bar/index.html => /foo/bar
863
876
var directory = pathname . substring ( 0 , pathname . lastIndexOf ( '/' ) ) ;
864
-
865
877
this . getAbsolutePath = function ( ) {
866
878
return directory + '/' + this . getPath ( ) ;
867
879
} ;
@@ -1021,7 +1033,11 @@ proto.loadNextPage = function() {
1021
1033
this . onPageError ( error , path ) ;
1022
1034
} . bind ( this ) ;
1023
1035
1024
- request ( path , this . options . responseType , onLoad , onError ) ;
1036
+ var onLast = function ( response ) {
1037
+ this . lastPageReached ( response , path ) ;
1038
+ } . bind ( this ) ;
1039
+
1040
+ request ( path , this . options . responseType , onLoad , onError , onLast ) ;
1025
1041
this . dispatchEvent ( 'request' , null , [ path ] ) ;
1026
1042
} ;
1027
1043
@@ -1219,7 +1235,7 @@ proto.stopPrefill = function() {
1219
1235
1220
1236
// -------------------------- request -------------------------- //
1221
1237
1222
- function request ( url , responseType , onLoad , onError ) {
1238
+ function request ( url , responseType , onLoad , onError , onLast ) {
1223
1239
var req = new XMLHttpRequest ( ) ;
1224
1240
req . open ( 'GET' , url , true ) ;
1225
1241
// set responseType document to return DOM
@@ -1231,6 +1247,8 @@ function request( url, responseType, onLoad, onError ) {
1231
1247
req . onload = function ( ) {
1232
1248
if ( req . status == 200 ) {
1233
1249
onLoad ( req . response ) ;
1250
+ } else if ( req . status == 204 ) {
1251
+ onLast ( req . response ) ;
1234
1252
} else {
1235
1253
// not 200 OK, error
1236
1254
var error = new Error ( req . statusText ) ;
@@ -1785,7 +1803,7 @@ return InfiniteScroll;
1785
1803
} ) ) ;
1786
1804
1787
1805
/*!
1788
- * Infinite Scroll v3.0.5
1806
+ * Infinite Scroll v3.0.6
1789
1807
* Automatically add next page
1790
1808
*
1791
1809
* Licensed GPLv3 for open source use
0 commit comments