File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ function InfiniteScroll( element, options ) {
3737
3838 if ( ! queryElem ) {
3939 console . error ( 'Bad element for InfiniteScroll: ' + ( queryElem || element ) ) ;
40+ return ;
4041 }
4142 element = queryElem ;
4243 // do not initialize twice on same element
Original file line number Diff line number Diff line change 3131 < script src ="unit/path.js "> </ script >
3232 < script src ="unit/page-load.js "> </ script >
3333 < script src ="unit/page-load-error.js "> </ script >
34+ < script src ="unit/page-index.js "> </ script >
3435 < script src ="unit/check-last-page.js "> </ script >
3536 < script src ="unit/prefill-window.js "> </ script >
3637 < script src ="unit/prefill-element.js "> </ script >
@@ -66,6 +67,12 @@ <h2>page load error</h2>
6667 < div class ="post "> page 1, post 1</ div >
6768 </ div >
6869
70+ < h2 > pageIndex</ h2 >
71+ < div class ="demo demo--page-index ">
72+ < div class ="post "> page 4, post 1</ div >
73+ </ div >
74+ < p > < a class ="page-index-next-link " href ="page/5.html "> Page 5</ a > </ p >
75+
6976 < h2 > check last page</ h2 >
7077 < div class ="demo demo--check-last-page ">
7178 < div class ="post "> page 1, post 1</ div >
Original file line number Diff line number Diff line change 1+ QUnit . test ( 'pageIndex' , function ( assert ) {
2+
3+ var demoElem = document . querySelector ( '.demo--page-index' ) ;
4+
5+ var infScroll = new InfiniteScroll ( demoElem , {
6+ path : '.page-index-next-link' ,
7+ history : false ,
8+ scrollThreshold : false ,
9+ } ) ;
10+
11+ assert . equal ( infScroll . pageIndex , 4 , 'pageIndex from path element' ) ;
12+
13+ infScroll . destroy ( ) ;
14+
15+ // pageIndex from URL with {{#}} path
16+ var prevURL = location . href ;
17+ // set URL with page number
18+ history . replaceState ( null , document . title , 'page/7' ) ;
19+ infScroll = new InfiniteScroll ( demoElem , {
20+ path : 'page/{{#}}' ,
21+ history : false ,
22+ scrollThreshold : false ,
23+ } ) ;
24+
25+ assert . equal ( infScroll . pageIndex , 7 , 'pageIndex from URL with {{#}}' ) ;
26+
27+ history . replaceState ( null , document . title , prevURL ) ;
28+
29+ } ) ;
You canβt perform that action at this time.
0 commit comments