11/*!
2- * Infinite Scroll PACKAGED v3.0.5
2+ * Infinite Scroll PACKAGED v3.0.6
33 * Automatically add next page
44 *
55 * Licensed GPLv3 for open source use
@@ -797,9 +797,13 @@ proto.updateGetPathTemplate = function( optPath ) {
797797 } . bind ( this ) ;
798798 // get pageIndex from location
799799 // 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?)' ) ;
801804 var templateRe = new RegExp ( regexString ) ;
802805 var match = location . href . match ( templateRe ) ;
806+
803807 if ( match ) {
804808 this . pageIndex = parseInt ( match [ 1 ] , 10 ) ;
805809 this . log ( 'pageIndex' , [ this . pageIndex , 'template string' ] ) ;
@@ -859,9 +863,17 @@ proto.updateGetAbsolutePath = function() {
859863 }
860864
861865 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+
862875 // /foo/bar/index.html => /foo/bar
863876 var directory = pathname . substring ( 0 , pathname . lastIndexOf ( '/' ) ) ;
864-
865877 this . getAbsolutePath = function ( ) {
866878 return directory + '/' + this . getPath ( ) ;
867879 } ;
@@ -1021,7 +1033,11 @@ proto.loadNextPage = function() {
10211033 this . onPageError ( error , path ) ;
10221034 } . bind ( this ) ;
10231035
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 ) ;
10251041 this . dispatchEvent ( 'request' , null , [ path ] ) ;
10261042} ;
10271043
@@ -1219,7 +1235,7 @@ proto.stopPrefill = function() {
12191235
12201236// -------------------------- request -------------------------- //
12211237
1222- function request ( url , responseType , onLoad , onError ) {
1238+ function request ( url , responseType , onLoad , onError , onLast ) {
12231239 var req = new XMLHttpRequest ( ) ;
12241240 req . open ( 'GET' , url , true ) ;
12251241 // set responseType document to return DOM
@@ -1231,6 +1247,8 @@ function request( url, responseType, onLoad, onError ) {
12311247 req . onload = function ( ) {
12321248 if ( req . status == 200 ) {
12331249 onLoad ( req . response ) ;
1250+ } else if ( req . status == 204 ) {
1251+ onLast ( req . response ) ;
12341252 } else {
12351253 // not 200 OK, error
12361254 var error = new Error ( req . statusText ) ;
@@ -1785,7 +1803,7 @@ return InfiniteScroll;
17851803} ) ) ;
17861804
17871805/*!
1788- * Infinite Scroll v3.0.5
1806+ * Infinite Scroll v3.0.6
17891807 * Automatically add next page
17901808 *
17911809 * Licensed GPLv3 for open source use
0 commit comments