Created
March 10, 2016 09:49
-
-
Save machouinard/993c07e82c7bddd55625 to your computer and use it in GitHub Desktop.
FacetWP inifinite scroll using button click
This file contains hidden or 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'; | |
} | |
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; | |
// #more-facet is the "Read More" button on the page | |
$( '#more-facet' ).on( 'click', function () { | |
var rows_loaded = (window.fwp_page * window.fwp_default_per_page); | |
if ( rows_loaded < window.fwp_total_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(); | |
$( this ).blur(); | |
} | |
} ); | |
} | |
} ); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I create a text link under posts like below and put your code to my custom javascript file.
<a href="#more-facet">Read More</a>
When I click the read more link, there is any change on page. What is my wrong?