Created
August 17, 2021 14:01
-
-
Save apsolut/169909b8d3044d83a60d12876c78d08f to your computer and use it in GitHub Desktop.
facetwp worked part
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
(function($) { | |
window.fwp_is_paging = false; | |
$(document).on('facetwp-refresh', function() { | |
if (! window.fwp_is_paging) { | |
window.fwp_page = 1; | |
FWP.extras.per_page = 'default'; | |
if (FWP.loaded) { | |
$('#pagination .container').prepend('<div class="decom-loading">Loading...</div>'); | |
} | |
} | |
window.fwp_is_paging = false; | |
}); | |
$(document).on('facetwp-loaded', function() { | |
window.fwp_total_rows = FWP.settings.pager.total_rows; | |
if (! FWP.loaded) { | |
window.fwp_default_per_page = FWP.settings.pager.per_page; | |
window.addEventListener('scroll', function() { | |
var element = document.querySelector('#colophon'); | |
var position = element.getBoundingClientRect(); | |
// checking for partial visibility | |
if(position.top < window.innerHeight && position.bottom >= 0) { | |
console.log('Element is partially visible in screen'); | |
var rows_loaded = (window.fwp_page * window.fwp_default_per_page); | |
if (rows_loaded < window.fwp_total_rows) { | |
console.log(rows_loaded + ' of ' + window.fwp_total_rows + ' rows'); | |
window.fwp_page++; | |
window.fwp_is_paging = true; | |
FWP.extras.per_page = (window.fwp_page * window.fwp_default_per_page); | |
FWP.soft_refresh = true; | |
FWP.refresh(); | |
} | |
} | |
}); | |
} | |
$('.decom-loading').remove(); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment