Skip to content

Commit 4e6a053

Browse files
committed
👷 build v3.0.0. v3 YAY!
1 parent 07ef13b commit 4e6a053

8 files changed

+58
-30
lines changed

‎.github/contributing.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
### Reduced test case required
44

5-
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).
5+
All bug reports and problem issues require a [**reduced test case**](https://css-tricks.com/reduced-test-cases/) or **live URL**.
66

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

11+
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).
12+
13+
+ [Scroll & append](https://codepen.io/desandro/pen/WOjqNM)
14+
+ [Scroll & append, vanilla JS](https://codepen.io/desandro/pen/WOpjMM)
15+
1116
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.
1217

1318
## Pull requests

‎.github/issue_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!-- 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. -->
22

3-
**Test case:** http://codepen.io/desandro/pen/azqbop
3+
**Test case:** http://codepen.io/desandro/pen/WOjqNM

‎dist/infinite-scroll.pkgd.js

+45-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Infinite Scroll PACKAGED v3.0.0-beta.1
2+
* Infinite Scroll PACKAGED v3.0.0
33
* Automatically add next page
44
*
55
* Licensed GPLv3 for open source use
@@ -601,6 +601,7 @@ function InfiniteScroll( element, options ) {
601601

602602
if ( !queryElem ) {
603603
console.error( 'Bad element for InfiniteScroll: ' + ( queryElem || element ) );
604+
return;
604605
}
605606
element = queryElem;
606607
// do not initialize twice on same element
@@ -626,6 +627,7 @@ function InfiniteScroll( element, options ) {
626627
InfiniteScroll.defaults = {
627628
// path: null,
628629
// hideNav: null,
630+
// debug: false,
629631
};
630632

631633
// create & destroy methods
@@ -727,7 +729,7 @@ var loggers = {
727729

728730
// log events
729731
proto.log = function( type, args ) {
730-
if ( !this.options.log ) {
732+
if ( !this.options.debug ) {
731733
return;
732734
}
733735
var message = '[InfiniteScroll] ' + type;
@@ -1039,6 +1041,7 @@ proto.appendNextPage = function( response, path ) {
10391041
this.appendItems( items, fragment );
10401042
this.isLoading = false;
10411043
this.dispatchEvent( 'append', null, [ response, path, items ] );
1044+
this.checkLastPage( response, path );
10421045
}.bind( this );
10431046

10441047
// TODO add hook for option to trigger appendReady
@@ -1047,27 +1050,22 @@ proto.appendNextPage = function( response, path ) {
10471050
} else {
10481051
appendReady();
10491052
}
1050-
1051-
this.checkLastPage( response, path );
10521053
};
10531054

10541055
proto.appendItems = function( items, fragment ) {
1055-
// get fragment if not provided
1056-
fragment = fragment || getItemsFragment( items );
1057-
if ( !fragment ) {
1056+
if ( !items || !items.length ) {
10581057
return;
10591058
}
1059+
// get fragment if not provided
1060+
fragment = fragment || getItemsFragment( items );
10601061
refreshScripts( fragment );
10611062
this.element.appendChild( fragment );
10621063
};
10631064

10641065
function getItemsFragment( items ) {
1065-
if ( !items || !items.length ) {
1066-
return;
1067-
}
10681066
// add items to fragment
10691067
var fragment = document.createDocumentFragment();
1070-
for ( var i=0; i < items.length; i++ ) {
1068+
for ( var i=0; items && i < items.length; i++ ) {
10711069
fragment.appendChild( items[i] );
10721070
}
10731071
return fragment;
@@ -1111,26 +1109,51 @@ proto.onAppendOutlayer = function( response, path, items ) {
11111109
this.options.outlayer.appended( items );
11121110
};
11131111

1114-
// ----- ----- //
1112+
// ----- checkLastPage ----- //
11151113

1116-
// check response for next element, set with path selector
1114+
// check response for next element
11171115
proto.checkLastPage = function( response, path ) {
1118-
// only works if path is selector
1119-
var cannotCheck = !this.options.checkLastPage ||
1120-
!this.isPathSelector;
1121-
if ( cannotCheck ) {
1116+
var checkLastPage = this.options.checkLastPage;
1117+
if ( !checkLastPage ) {
11221118
return;
11231119
}
1124-
var pathElem = response.querySelector( this.options.path );
1125-
if ( pathElem ) {
1126-
// page has next element, keep going
1120+
1121+
var pathOpt = this.options.path;
1122+
// if path is function, check if next path is truthy
1123+
if ( typeof pathOpt == 'function' ) {
1124+
var nextPath = this.getPath();
1125+
if ( !nextPath ) {
1126+
this.lastPageReached( response, path );
1127+
return;
1128+
}
1129+
}
1130+
// get selector from checkLastPage or path option
1131+
var selector;
1132+
if ( typeof checkLastPage == 'string' ) {
1133+
selector = checkLastPage;
1134+
} else if ( this.isPathSelector ) {
1135+
// path option is selector string
1136+
selector = pathOpt;
1137+
}
1138+
// check last page for selector
1139+
// bail if no selector or not document response
1140+
if ( !selector || !response.querySelector ) {
11271141
return;
11281142
}
1129-
// no next selector, last page hit
1143+
// check if response has selector
1144+
var nextElem = response.querySelector( selector );
1145+
if ( !nextElem ) {
1146+
this.lastPageReached( response, path );
1147+
}
1148+
};
1149+
1150+
proto.lastPageReached = function( response, path ) {
11301151
this.canLoad = false;
11311152
this.dispatchEvent( 'last', null, [ response, path ] );
11321153
};
11331154

1155+
// ----- error ----- //
1156+
11341157
proto.onPageError = function( error, path ) {
11351158
this.isLoading = false;
11361159
this.canLoad = false;
@@ -1728,7 +1751,7 @@ return InfiniteScroll;
17281751
}));
17291752

17301753
/*!
1731-
* Infinite Scroll v3.0.0-beta.1
1754+
* Infinite Scroll v3.0.0
17321755
* Automatically add next page
17331756
*
17341757
* Licensed GPLv3 for open source use

‎dist/infinite-scroll.pkgd.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Infinite Scroll v3.0.0-beta.1
2+
* Infinite Scroll v3.0.0
33
* Automatically add next page
44
*
55
* Licensed GPLv3 for open source use

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "infinite-scroll",
3-
"version": "3.0.0-beta.1",
3+
"version": "3.0.0",
44
"description": "Automatically add next page",
55
"main": "js/index.js",
66
"files": [

‎test/unit/history-window.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ QUnit.test( 'history window', function( assert ) {
1414
// debug: true,
1515
});
1616

17-
var page1Top = getTop( demoElem );
17+
var page1Top = getTop( demoElem ) - 100;
1818
var page2Top;
1919
var page3Top;
2020

‎test/unit/outlayer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ QUnit.test( 'outlayer', function( assert ) {
7777
infScroll.once( 'append', function( response, path, items ) {
7878
assert.equal( items.length, 0, 'appended 0 items' );
7979
done();
80-
})
80+
});
8181
infScroll.loadNextPage();
8282
}
8383

0 commit comments

Comments
 (0)