10 months ago
<?php
/** reloads bricks accordian after facet reloads **/
add_action( 'wp_footer', function() {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
bricksAccordion();
});
</script>
<?php
}, 100 );
1 year ago
<?php
add_action( 'wp_footer', function() {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
EleCustomSkinItemLink();
});
</script>
<?php
}, 100 );
4 months ago
<?php
/** close flyout on facetwp-loaded so that the user doesn't need to close after facet refreshes **/
add_action( 'facetwp_scripts', function() { ?>
<script>
(function($) {
document.addEventListener('facetwp-loaded', function() {
if (FWP.loaded && $('.facetwp-flyout').hasClass('active') ) {
FWP.flyout.close();
}
});
})(fUtil);
</script>
<?php } );
12 hours ago
<?php
add_action( 'facetwp_scripts', function() {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
if ( FWP.loaded ) {
jQuery('.wp-audio-shortcode').mediaelementplayer();
}
});
</script>
<?php
}, 100 );
7 days ago
<?php
// Adds wrappers with class "column-wrapper" surrounding top-level 'facetwp-checkbox' elements and their following sibling 'facetwp-depth' elements, for column styling
// Replace 'myfacetname' with the name of your facet
add_action( 'facetwp_scripts', function() {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
// Get all top-level facetwp-checkbox elements
var checkboxes = document.querySelectorAll('.facetwp-facet-myfacetname > .facetwp-checkbox');
// Loop through each checkbox
checkboxes.forEach(function(checkbox) {
// Create a new div element for the wrapper
var wrapper = document.createElement('div');
wrapper.classList.add('column-wrapper');
// Find the next sibling div with class facetwp-depth
var depth = checkbox.nextElementSibling;
// Append the wrapper before the current checkbox
checkbox.parentNode.insertBefore(wrapper, checkbox);
// Append the checkbox element to the wrapper
wrapper.appendChild(checkbox);
// Check if the depth element exists and has the class facetwp-depth
if (depth && depth.classList.contains('facetwp-depth')) {
// Append the depth element to the wrapper
wrapper.appendChild(depth);
}
});
});
</script>
<?php
}, 100 );
1 week ago
<?php
/** Trigger rocket-DOMContentLoaded or DOMContentLoaded after using facets
** Change 'rocket-DOMContentLoaded' to 'DOMContentLoaded' if you are not using WP Rocket lazy load
**/
add_action('facetwp_scripts', function () {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
if (FWP.loaded) {
window.document.dispatchEvent(new Event("rocket-DOMContentLoaded", {
bubbles: true,
cancelable: true
}));
}
});
</script>
<?php
}, 100);
3 weeks ago
<?php
// Add to your (child) theme's functions.php
add_action( 'facetwp_scripts', function() {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
if (FWP.loaded) {
FOOBOX.init();
}
});
</script>
<?php
}, 100 );
1 month ago
<?php
// Changes 'mi' to 'miles' in a Proximity facet's radius dropdown
add_action('facetwp_scripts', function () {
?>
<script>
(function($) {
document.addEventListener('facetwp-loaded', function() {
let radiusdropdown = document.querySelector('.facetwp-radius-dropdown');
radiusdropdown.querySelectorAll('option').forEach(option => {
if (option.textContent.trim().endsWith('mi')) {
const newOptionText = option.textContent.replace(/mi\b/g, 'miles'); // Replace 'mi' with 'miles' if it is at the end of the option string
option.textContent = newOptionText;
}
});
});
})(fUtil);
</script>
<?php
}, 100);
2 months ago
<?php
// Hides a facet if there is only one option left
// Replace 'my_facet_name' with the name of your facet (4x)
add_action( 'facetwp_scripts', function() { ?>
<script>
(function($) {
document.addEventListener('facetwp-loaded', function() {
if ( FWP.settings.num_choices.my_facet_name !== 'undefined' && FWP.settings.num_choices.my_facet_name < 2 ) {
$('.facetwp-facet-my_facet_name').addClass( 'facetwp-hidden' );
} else {
$('.facetwp-facet-my_facet_name').removeClass( 'facetwp-hidden' );
}
});
})(fUtil);
</script>
<?php } );
3 months ago
<?php
/**
** change facet1 to the name of your first facet (the facet to check selection)
** facet2 to the name of your second facet (to be disabled)
**/
add_action( 'facetwp_scripts', function() {
?>
<script>
(function($) {
document.addEventListener('facetwp-loaded', function() {
if ( 'undefined' !== typeof FWP.facets['facet1'] && FWP.facets['facet1'].length > 0 ) {
$( '.facetwp-facet-facet2 select' ).attr('disabled', 'disabled');
}
});
})(fUtil);
</script>
<?php
}, 100 );