<?php
// Makes ghost Checkboxes facet choices clickable.
// When a ghost choice is clicked, it is selected while at the same time resetting all other facets,
// including the ones which choices caused the ghosts in the first place, for example a Search facet.
// Note: does not update Pager facets or Result Counts,
add_action( 'facetwp_scripts', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
// Identify disabled (ghosted) entries by their CSS class or attribute.
$('.facetwp-checkbox.disabled').each(function() {
var $entry = $(this);
// Remove the disabled attribute to make it clickable.
// Optionally style these clickable ghosts with the .facetwp-ghost class.
$entry.removeClass('disabled').addClass('facetwp-ghost');
// Handle click event to apply the corresponding facet.
$entry.on('click', function() {
var facetname = $entry.closest('.facetwp-facet').data('name');
var facetvalue = $entry.data('value');
// Clear all facets except the current one.
FWP.facets = {};
FWP.facets[facetname] = [facetvalue];
// Refresh
FWP.is_reset = true; // Don't parse facets.
FWP.fetchData();
FWP.setHash(); // Update the URL variables.
});
});
});
})(jQuery);
</script>
<?php
}, 100 );