Make ghost Checkboxes facet choices clickable and reset other facets

// 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() {

    (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.

          // Handle click event to apply the corresponding facet.
          $entry.on('click', function() {
            var facetname = $entry.closest('.facetwp-facet').data('name');
            var facetvalue = $'value');

            // Clear all facets except the current one.
            FWP.facets = {};
            FWP.facets[facetname] = [facetvalue];

            // Refresh
            FWP.is_reset = true; // Don't parse facets.
            FWP.setHash(); // Update the URL variables.


}, 100 );