diff --git a/js/checkbox-widget.js b/js/checkbox-widget.js index 608cfc0..821424e 100644 --- a/js/checkbox-widget.js +++ b/js/checkbox-widget.js @@ -8,37 +8,30 @@ "use strict"; Drupal.facets = {}; - Drupal.behaviors.facetsCheckboxWidget = { attach: function (context, settings) { Drupal.facets.makeCheckboxes(); } }; - /** * Turns all facet links into checkboxes. - * Ensures the facet is disabled if a link is clicked. */ Drupal.facets.makeCheckboxes = function () { - - var $checkbox_facets = $('.js-facets-checkbox-links'), - $links = $('.facet-item a', $checkbox_facets); - // Find all checkbox facet links and give them a checkbox. - $links.once('facets-makeCheckbox').each(Drupal.facets.makeCheckbox); - } - + var $links = $('.js-facets-checkbox-links .facet-item a'); + $links.once('facets-checkbox-transform').each(Drupal.facets.makeCheckbox); + }; /** - * Replace an unclick link with a checked checkbox. + * Replace a link with a checked checkbox. */ Drupal.facets.makeCheckbox = function () { var $link = $(this); var active = $link.hasClass('is-active'); var description = $link.html(); var href = $link.attr('href'); - var id = $link.attr('id'); + var id = $link.data('facet-id'); var checkbox = $(''); var label = $(''); @@ -55,8 +48,7 @@ $link.before(checkbox).before(label).hide(); - } - + }; /** * Disable all facet links and checkboxes in the facet and apply a 'disabled' @@ -66,8 +58,7 @@ $facet.addClass('facets-disabled'); $('input.facets-checkbox').click(Drupal.facets.preventDefault); $('input.facetapi-checkbox', $facet).attr('disabled', true); - } - + }; /** * Event listener for easy prevention of event propagation. diff --git a/src/Plugin/facets/widget/CheckboxWidget.php b/src/Plugin/facets/widget/CheckboxWidget.php index d0d51fb..a9f82a9 100644 --- a/src/Plugin/facets/widget/CheckboxWidget.php +++ b/src/Plugin/facets/widget/CheckboxWidget.php @@ -69,7 +69,7 @@ class CheckboxWidget extends LinksWidget { */ protected function buildListItems(ResultInterface $result) { $items = parent::buildListItems($result); - $items['#attributes']['id'] = $this->facet->getUrlAlias() . '-' . $result->getRawValue(); + $items['#attributes']['data-facet-id'] = $this->facet->getUrlAlias() . '-' . $result->getRawValue(); return $items; } }