Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Forked from zacholas/facetwp-isotope.js
Created December 2, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/1a4cc5898e142d039ffb86794a6df7de to your computer and use it in GitHub Desktop.
Save mgibbs189/1a4cc5898e142d039ffb86794a6df7de to your computer and use it in GitHub Desktop.
jQuery(document).ready(function($) {
//* FacetWP Isotope
var fwpScrollToBtn = false;
var $grid = $('.fwpl-layout');
$grid.imagesLoaded(function() {
//* Wrapped in a short timeout function because $grid.imagesLoaded doesn't reliably lay out correctly
setTimeout(function(){
$grid.isotope({
itemSelector: '.fwpl-result',
});
}, 250);
});
$(document).on('facetwp-loaded', function() {
if (FWP.loaded) {
$grid = $('.fwpl-layout');
$grid.isotope('destroy');
$grid.isotope({
itemSelector: '.fwpl-result',
});
//* Scroll to the button of the results on click of load more since we're destroying the listing
if(fwpScrollToBtn === true){
var $loadMoreBtn = $('.facetwp-load-more');
if($loadMoreBtn.length){
$([document.documentElement, document.body]).animate({
scrollTop:
$loadMoreBtn.offset().top // button scrolled distance from the top of the screen
- window.innerHeight // window height (to get it scrolled where the button is at the bottom of the screen vs top)
+ $loadMoreBtn.outerHeight() // height of the btn
+ 20 // padding from the bottom of the screen
}, 250);
}
}
}
});
$(document).on('click', '.facetwp-load-more', function () {
fwpScrollToBtn = true;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment