Created
May 3, 2017 21:48
-
-
Save rogerlos/1d330f6ce7870d57a4d4a026440c7f84 to your computer and use it in GitHub Desktop.
Fires a new FacetWP trigger, 'facetwp-done', when FacetWP is finished rendering content; FacetWP's own triggers are called before rendering is complete.
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
/** | |
* Procedural JS that ensures FacetWP has fully rendered all of its various pieces; | |
* triggers 'facetwp-done' when everything is rendered. | |
* | |
* Useful if you need to change the HTML within '.facetwp-selections', for example. | |
* | |
* 'waitlimit' : number of times to allow wait_for_facetwp() to be called | |
* 'waitime' : miliseconds between calls | |
*/ | |
jQuery( document ).ready( function ( $ ) { | |
var waiter = false, | |
waitcounter = 0, | |
waitlimit = 20, | |
waittime = 300; | |
if ( typeof( FWP ) !== 'undefined' ) | |
$( document ).on( 'facetwp-loaded, facetwp-refresh', facetwp_now_waiting ); | |
function wait_for_facetwp() { | |
if ( FWP.is_refresh === true || FWP.loaded === false ) { | |
facetwp_now_waiting(); | |
} else if ( FWP.is_refresh === false && FWP.loaded === true ) { | |
facetwp_done(); | |
} | |
} | |
function facetwp_now_waiting() { | |
waitcounter ++; | |
if ( waitcounter <= waitlimit ) | |
waiter = window.setTimeout( wait_for_facetwp, waittime ); | |
else | |
reset_wait(); | |
} | |
function reset_wait() { | |
waitcounter = 0; | |
waiter = false; | |
} | |
function facetwp_done() { | |
reset_wait(); | |
$( document ).trigger( 'facetwp-done' ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment