@@ -94,6 +94,7 @@ proto.appendNextPage = function( response, path ) {
9494 this . appendItems ( items , fragment ) ;
9595 this . isLoading = false ;
9696 this . dispatchEvent ( 'append' , null , [ response , path , items ] ) ;
97+ this . checkLastPage ( response , path ) ;
9798 } . bind ( this ) ;
9899
99100 // TODO add hook for option to trigger appendReady
@@ -102,8 +103,6 @@ proto.appendNextPage = function( response, path ) {
102103 } else {
103104 appendReady ( ) ;
104105 }
105-
106- this . checkLastPage ( response , path ) ;
107106} ;
108107
109108proto . appendItems = function ( items , fragment ) {
@@ -166,26 +165,35 @@ proto.onAppendOutlayer = function( response, path, items ) {
166165 this . options . outlayer . appended ( items ) ;
167166} ;
168167
169- // ----- ----- //
168+ // ----- checkLastPage ----- //
170169
171- // check response for next element, set with path selector
170+ // check response for next element
172171proto . checkLastPage = function ( response , path ) {
173- // only works if path is selector
174- var cannotCheck = ! this . options . checkLastPage ||
175- ! this . isPathSelector ;
176- if ( cannotCheck ) {
172+ var checkLastPage = this . options . checkLastPage ;
173+ // get selector from checkLastPage or path option
174+ var selector ;
175+ if ( typeof checkLastPage == 'string' ) {
176+ selector = checkLastPage ;
177+ } else if ( this . isPathSelector ) {
178+ selector = this . options . path ;
179+ }
180+ // bail if checkLastPage disabled or no selector or not document response
181+ if ( ! checkLastPage || ! selector || ! response . querySelector ) {
177182 return ;
178183 }
179- var pathElem = response . querySelector ( this . options . path ) ;
180- if ( pathElem ) {
181- // page has next element, keep going
184+ // check if response has selector
185+ var nextElem = response . querySelector ( selector ) ;
186+ if ( nextElem ) {
187+ // page has selector element, keep going
182188 return ;
183189 }
184190 // no next selector, last page hit
185191 this . canLoad = false ;
186192 this . dispatchEvent ( 'last' , null , [ response , path ] ) ;
187193} ;
188194
195+ // ----- error ----- //
196+
189197proto . onPageError = function ( error , path ) {
190198 this . isLoading = false ;
191199 this . canLoad = false ;
0 commit comments