Infinite scroll for FacetWP
/* globals FWP */ | |
/** | |
* JavaScript for FacetWP Infinite Scroll | |
*/ | |
(function( $ ) { | |
'use-strict'; | |
var throttleTimer = null; | |
var throttleDelay = 100; | |
function ScrollHandler() { | |
clearTimeout( throttleTimer ); | |
throttleTimer = setTimeout(function() { | |
if ( $( window ).scrollTop() !== $( document ).height() - $( window ).height() ) { | |
return; | |
} | |
if ( FWP.settings.pager.page < FWP.settings.pager.total_pages ) { | |
FWP.paged = parseInt( FWP.settings.pager.page ) + 1; | |
FWP.is_load_more = true; | |
FWP.soft_refresh = false; | |
FWP.refresh(); | |
} | |
}, throttleDelay ); | |
} | |
wp.hooks.addFilter( 'facetwp/template_html', function( resp, params ) { | |
if ( FWP.is_load_more ) { | |
FWP.is_load_more = false; | |
$( '.facetwp-template' ).append( params.html ); | |
return true; | |
} | |
return resp; | |
}); | |
$( document ).on( 'facetwp-loaded', function() { | |
if ( ! FWP.loaded ) { | |
$( window ).off( 'scroll', ScrollHandler ).on( 'scroll', ScrollHandler ); | |
} | |
}); | |
})( jQuery ); |
This comment has been minimized.
This comment has been minimized.
I'd like that too. Currently I get an error: |
This comment has been minimized.
This comment has been minimized.
@larsvdd Try this one. (function( $ ) { var throttleTimer = null; $(function() {
}); |
This comment has been minimized.
This comment has been minimized.
The version with the $win and $doc vars works for me. How can I bind the facetwp-loading loader graphic to this? There is no indication more results are available. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Hi Rob - any pointers on how to use your FacetWP Infinite Scroll script?
Thanks!