Forked from hirejordansmith/facet-wp-infinite-scroll.js
Created
July 2, 2019 12:25
-
-
Save Giannisduke/ca185e938025f20d64309b44a671254f to your computer and use it in GitHub Desktop.
Infinite scroll for FacetWP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* globals FWP */ | |
/** | |
* JavaScript for FacetWP Infinite Scroll | |
*/ | |
( function( $ ) { | |
'use-strict'; | |
var throttleTimer = null; | |
var throttleDelay = 100; | |
$( function() { | |
var $win = $( window ); | |
var $doc = $( document ); | |
function ScrollHandler() { | |
clearTimeout( throttleTimer ); | |
throttleTimer = setTimeout( function() { | |
if ( $( window ) | |
.scrollTop() + $( window ) | |
.height() > $( document ) | |
.height() - 400 ) { | |
console.log( 'aaaaaaaaaaaaaa' ); | |
} else { | |
console.log( 'bbbbbbbbbbbbb' ); | |
return; | |
} | |
console.log( 'your message 3' ); | |
if ( FWP.settings.pager.page < FWP.settings.pager.total_pages ) { | |
FWP.paged = parseInt( FWP.settings.pager.page ) + 1; | |
FWP.is_load_more = true; | |
//alert("start"); | |
if ( jQuery( '.mycurellsloadder' ) | |
.length == 0 ) { | |
jQuery( ".woocommerce-pagination" ) | |
.append( "<div class='mycurellsloadder'></div>" ); | |
} | |
FWP.soft_refresh = false; | |
FWP.refresh(); | |
} | |
}, throttleDelay ); | |
} | |
wp.hooks.addFilter( 'facetwp/template_html', function( resp, params ) { | |
if ( FWP.is_load_more ) { | |
// alert("end"); | |
jQuery( ".mycurellsloadder" ) | |
.remove(); | |
FWP.is_load_more = false; | |
$( '.facetwp-template' ) | |
.append( params.html ); | |
return true; | |
} | |
return resp; | |
} ); | |
$doc.on( 'facetwp-loaded', function() { | |
if ( !FWP.loaded ) { | |
console.log( 'your message' ); | |
$win.off( 'scroll', ScrollHandler ) | |
.on( 'scroll', ScrollHandler ); | |
} | |
} ); | |
} ); | |
} )( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment