kpetrowski
11/1/2018 - 5:57 PM

FacetWP Infinite Scroll & Loading

<!-- FACETWP INFINITE SCROLL & LOADING -->
<script>
(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';
        }

        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).scroll(function() {
                if ($(window).scrollTop() == $(document).height() - $(window).height()) {
                    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();
                    }
                }
            });
        }
    });
})(jQuery);
</script>