Skip to content

Commit

Permalink
👷 build v3.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Apr 27, 2019
1 parent 9f9ccf3 commit 7270f45
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
30 changes: 24 additions & 6 deletions dist/infinite-scroll.pkgd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Infinite Scroll PACKAGED v3.0.5
* Infinite Scroll PACKAGED v3.0.6
* Automatically add next page
*
* Licensed GPLv3 for open source use
Expand Down Expand Up @@ -797,9 +797,13 @@ proto.updateGetPathTemplate = function( optPath ) {
}.bind( this );
// get pageIndex from location
// convert path option into regex to look for pattern in location
var regexString = optPath.replace( '{{#}}', '(\\d\\d?\\d?)' );
// escape query (?) in url, allows for parsing GET parameters
var regexString = optPath
.replace( /(\\\?|\?)/, '\\?' )
.replace( '{{#}}', '(\\d\\d?\\d?)' );
var templateRe = new RegExp( regexString );
var match = location.href.match( templateRe );

if ( match ) {
this.pageIndex = parseInt( match[1], 10 );
this.log( 'pageIndex', [ this.pageIndex, 'template string' ] );
Expand Down Expand Up @@ -859,9 +863,17 @@ proto.updateGetAbsolutePath = function() {
}

var pathname = location.pathname;
// query parameter #829. example.com/?pg=2
var isQuery = path.match( /^\?/ );
if ( isQuery ) {
this.getAbsolutePath = function() {
return pathname + this.getPath();
};
return;
}

// /foo/bar/index.html => /foo/bar
var directory = pathname.substring( 0, pathname.lastIndexOf('/') );

this.getAbsolutePath = function() {
return directory + '/' + this.getPath();
};
Expand Down Expand Up @@ -1021,7 +1033,11 @@ proto.loadNextPage = function() {
this.onPageError( error, path );
}.bind( this );

request( path, this.options.responseType, onLoad, onError );
var onLast = function( response ) {
this.lastPageReached( response, path );
}.bind( this );

request( path, this.options.responseType, onLoad, onError, onLast );
this.dispatchEvent( 'request', null, [ path ] );
};

Expand Down Expand Up @@ -1219,7 +1235,7 @@ proto.stopPrefill = function() {

// -------------------------- request -------------------------- //

function request( url, responseType, onLoad, onError ) {
function request( url, responseType, onLoad, onError, onLast ) {
var req = new XMLHttpRequest();
req.open( 'GET', url, true );
// set responseType document to return DOM
Expand All @@ -1231,6 +1247,8 @@ function request( url, responseType, onLoad, onError ) {
req.onload = function() {
if ( req.status == 200 ) {
onLoad( req.response );
} else if ( req.status == 204 ) {
onLast( req.response );
} else {
// not 200 OK, error
var error = new Error( req.statusText );
Expand Down Expand Up @@ -1785,7 +1803,7 @@ return InfiniteScroll;
}));

/*!
* Infinite Scroll v3.0.5
* Infinite Scroll v3.0.6
* Automatically add next page
*
* Licensed GPLv3 for open source use
Expand Down
Loading

0 comments on commit 7270f45

Please sign in to comment.