Skip to content

Commit

Permalink
πŸ‘· build v3.0.0. v3 YAY!
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Jun 22, 2017
1 parent 07ef13b commit 4e6a053
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 30 deletions.
7 changes: 6 additions & 1 deletion .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

### Reduced test case required

All bug reports and problem issues require a [**reduced test case**](https://css-tricks.com/reduced-test-cases/) or **live URL**. Create one by forking any one of the [CodePen demos](https://codepen.io/desandro/tag/infinite-scroll-v3-docs) from [the docs](https://infinite-scroll.com).
All bug reports and problem issues require a [**reduced test case**](https://css-tricks.com/reduced-test-cases/) or **live URL**.

+ A reduced test case clearly demonstrates the bug or issue.
+ It contains the bare minimum HTML, CSS, and JavaScript required to demonstrate the bug.
+ A link to your production site is **not** a reduced test case.

Create one by forking any one of the [CodePen demos](https://codepen.io/desandro/tag/infinite-scroll-v3-docs) from [the docs](https://infinite-scroll.com).

+ [Scroll & append](https://codepen.io/desandro/pen/WOjqNM)
+ [Scroll & append, vanilla JS](https://codepen.io/desandro/pen/WOpjMM)

Providing a reduced test case is the best way to get your issue addressed. They help you point out the problem. They help me verify and debug the problem. They help others understand the problem. Without a reduced test case or live URL, your issue may be closed.

## Pull requests
Expand Down
2 changes: 1 addition & 1 deletion .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- Thanks for submitting an issue! All bug reports and problem issues require a **reduced test case** or **live URL**. Create one by forking any one of the CodePen examples from the docs. See guidelines link above. -->

**Test case:** http://codepen.io/desandro/pen/azqbop
**Test case:** http://codepen.io/desandro/pen/WOjqNM
67 changes: 45 additions & 22 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.0-beta.1
* Infinite Scroll PACKAGED v3.0.0
* Automatically add next page
*
* Licensed GPLv3 for open source use
Expand Down Expand Up @@ -601,6 +601,7 @@ function InfiniteScroll( element, options ) {

if ( !queryElem ) {
console.error( 'Bad element for InfiniteScroll: ' + ( queryElem || element ) );
return;
}
element = queryElem;
// do not initialize twice on same element
Expand All @@ -626,6 +627,7 @@ function InfiniteScroll( element, options ) {
InfiniteScroll.defaults = {
// path: null,
// hideNav: null,
// debug: false,
};

// create & destroy methods
Expand Down Expand Up @@ -727,7 +729,7 @@ var loggers = {

// log events
proto.log = function( type, args ) {
if ( !this.options.log ) {
if ( !this.options.debug ) {
return;
}
var message = '[InfiniteScroll] ' + type;
Expand Down Expand Up @@ -1039,6 +1041,7 @@ proto.appendNextPage = function( response, path ) {
this.appendItems( items, fragment );
this.isLoading = false;
this.dispatchEvent( 'append', null, [ response, path, items ] );
this.checkLastPage( response, path );
}.bind( this );

// TODO add hook for option to trigger appendReady
Expand All @@ -1047,27 +1050,22 @@ proto.appendNextPage = function( response, path ) {
} else {
appendReady();
}

this.checkLastPage( response, path );
};

proto.appendItems = function( items, fragment ) {
// get fragment if not provided
fragment = fragment || getItemsFragment( items );
if ( !fragment ) {
if ( !items || !items.length ) {
return;
}
// get fragment if not provided
fragment = fragment || getItemsFragment( items );
refreshScripts( fragment );
this.element.appendChild( fragment );
};

function getItemsFragment( items ) {
if ( !items || !items.length ) {
return;
}
// add items to fragment
var fragment = document.createDocumentFragment();
for ( var i=0; i < items.length; i++ ) {
for ( var i=0; items && i < items.length; i++ ) {
fragment.appendChild( items[i] );
}
return fragment;
Expand Down Expand Up @@ -1111,26 +1109,51 @@ proto.onAppendOutlayer = function( response, path, items ) {
this.options.outlayer.appended( items );
};

// ----- ----- //
// ----- checkLastPage ----- //

// check response for next element, set with path selector
// check response for next element
proto.checkLastPage = function( response, path ) {
// only works if path is selector
var cannotCheck = !this.options.checkLastPage ||
!this.isPathSelector;
if ( cannotCheck ) {
var checkLastPage = this.options.checkLastPage;
if ( !checkLastPage ) {
return;
}
var pathElem = response.querySelector( this.options.path );
if ( pathElem ) {
// page has next element, keep going

var pathOpt = this.options.path;
// if path is function, check if next path is truthy
if ( typeof pathOpt == 'function' ) {
var nextPath = this.getPath();
if ( !nextPath ) {
this.lastPageReached( response, path );
return;
}
}
// get selector from checkLastPage or path option
var selector;
if ( typeof checkLastPage == 'string' ) {
selector = checkLastPage;
} else if ( this.isPathSelector ) {
// path option is selector string
selector = pathOpt;
}
// check last page for selector
// bail if no selector or not document response
if ( !selector || !response.querySelector ) {
return;
}
// no next selector, last page hit
// check if response has selector
var nextElem = response.querySelector( selector );
if ( !nextElem ) {
this.lastPageReached( response, path );
}
};

proto.lastPageReached = function( response, path ) {
this.canLoad = false;
this.dispatchEvent( 'last', null, [ response, path ] );
};

// ----- error ----- //

proto.onPageError = function( error, path ) {
this.isLoading = false;
this.canLoad = false;
Expand Down Expand Up @@ -1728,7 +1751,7 @@ return InfiniteScroll;
}));

/*!
* Infinite Scroll v3.0.0-beta.1
* Infinite Scroll v3.0.0
* Automatically add next page
*
* Licensed GPLv3 for open source use
Expand Down
4 changes: 2 additions & 2 deletions dist/infinite-scroll.pkgd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Infinite Scroll v3.0.0-beta.1
* Infinite Scroll v3.0.0
* Automatically add next page
*
* Licensed GPLv3 for open source use
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "infinite-scroll",
"version": "3.0.0-beta.1",
"version": "3.0.0",
"description": "Automatically add next page",
"main": "js/index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion test/unit/history-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ QUnit.test( 'history window', function( assert ) {
// debug: true,
});

var page1Top = getTop( demoElem );
var page1Top = getTop( demoElem ) - 100;
var page2Top;
var page3Top;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/outlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ QUnit.test( 'outlayer', function( assert ) {
infScroll.once( 'append', function( response, path, items ) {
assert.equal( items.length, 0, 'appended 0 items' );
done();
})
});
infScroll.loadNextPage();
}

Expand Down

1 comment on commit 4e6a053

@fakefarm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@desandro, Congrats!! Looking forward to digging into the source code...

Please sign in to comment.