Gists

1 year ago
<?php
/** close flyout on facetwp-loaded so that the user doesn't need to close after facet refreshes **/
add_action( 'wp_head', function() { ?>
    <script>
        (function($) {
            $(document).on('facetwp-loaded', function() {
              if (FWP.loaded && $('.facetwp-flyout').hasClass('active') ) {
                  FWP.flyout.close();
              }
          });
        })(jQuery);
    </script>
<?php } );
3 hours ago
/** hide entire section of facets if none have options
 ** facet-wrap is individual facet wrapper element
 ** facetwp-wrapper is wrapper elenement around all facets (grandparent)
 **/
function($) {
    document.addEventListener('facetwp-loaded', function() {
        var $all = 0; // for checking all facets
        $.each(FWP.settings.num_choices, function(key, val) {
        var $facet = $('.facetwp-facet-' + key);
        var $parent = $facet.closest('.facet-wrap');
        var $flyout = $facet.closest('.flyout-row');
        if ($parent.length || $flyout.length) {
            var $which = $parent.length ? $parent : $flyout;
            (0 === val) ? $which.hide() : $which.show();
        }
            $all += val; // add any values from this facet
        });
        (0 === $all) ? $('.facetwp-wrapper').hide() : $('.facetwp-wrapper').show(); // show hide wrapper depending on whether any facets had values
    });
})(jQuery);
4 weeks ago
<?php
add_action( 'wp_head', function() {
?>

<script>
(function($) {
    document.addEventListener('facetwp-loaded', function() {
        var classList = document.body.className.split(/\s+/);
        for (var i = 0; i < classList.length; i++) {
            if (classList[i].includes("-community")) {
              $('body').removeClass( classList[i] );
            }
        }
        if ( 'undefined' !== typeof FWP.facets['state'] && 1 === FWP.facets['state'].length ) {
          $('body').addClass( FWP.facets['state'][0] + '-community' );
        }
     });
})(jQuery);
</script>

<?php
}, 100 );
4 weeks ago
<?php
/** reinitialize videos **/    
add_action( 'wp_head', function() {
?>

<script>
(function($) {
    document.addEventListener('facetwp-loaded', function() {
        $('.fifu-video').each(function (index) {
        	$(this).css('opacity', 1);
    	});
    	replaceVideoThumb($);
     });
})(jQuery);
</script>

<?php
}, 100 );
2 months ago
<?php

add_action( 'wp_head', function() {
?>

<script>
(function($) {
    const isExternalURL = (url) => new URL(url).origin !== location.origin;

    document.addEventListener('facetwp-loaded', function() {
        $('.facetwp-template a').each(function() {
            var $this = $(this);
            if (isExternalURL($this.attr('href'))) {
                $this.attr('rel', 'nofollow');
            }
        });
     });
})(jQuery);
</script>

<?php
}, 100 );
2 months ago
<?php

add_action( 'wp_head', function() {
?>

<script>
(function($) {
    document.addEventListener('facetwp-loaded', function() {
        $(document).triggerHandler('ajaxComplete');
     });
})(jQuery);
</script>

<?php
}, 100 );
6 months ago
// Based on https://www.advancedcustomfields.com/resources/google-map/#template-usage
// Replace the following code (towards the bottom of the JS):

$(document).ready(function(){
    $('.acf-map').each(function(){
        var map = initMap( $(this) );
    });
});


// With:

$(document).on('facetwp-loaded', function() {
    $('.acf-map').each(function(){
        var map = initMap( $(this) );
    });
});
7 months ago
(function($) {
    document.addEventListener( "facetwp-loaded", function() {
        $( ".facetwp-checkbox.checked .facetwp-expand" ).trigger( "click" );
    });
})(jQuery);
1 month ago
add_action( 'wp_head', function() {
?>
<script>
(function($) {
	$(document).on('facetwp-loaded', function() {
		if ('' != FWP.buildQueryString()) {
			$('.facetwp-template').show();
		} else {
			$('.facetwp-template').hide();
		}
	 });
})(jQuery);
</script>
<?php
}, 100 );
11 months ago
<script>

(function($) {
    $(document).on('facetwp-loaded', function() {
        var $grid = $('.columns-3').imagesLoaded(function() {
            $grid.isotope({
                layoutMode: 'masonry',
                itemSelector : '.product',
                masonry: {
                    columnWidth: '.product',
                }
            });
        });
    });
})(jQuery);

</script>