PageSourceSearch

https://www.livreshebdo.fr/modules/contrib/facets/js/checkbox-widget.js?v=8.9.13

js livreshebdo.fr collected 2026-10-02 02:47:16 UTC 2,953 bytes, 104 lines download raw bytes

1/**
2 * @file
3 * Transforms links into checkboxes.
4 */
5
6(function ($, Drupal) {
7
8  'use strict';
9
10  Drupal.facets = Drupal.facets || {};
11  Drupal.behaviors.facetsCheckboxWidget = {
12    attach: function (context) {
13      Drupal.facets.makeCheckboxes(context);
14    }
15  };
16
17  /**
18   * Turns all facet links into checkboxes.
19   */
20  Drupal.facets.makeCheckboxes = function (context) {
21    // Find all checkbox facet links and give them a checkbox.
22    var $checkboxWidgets = $('.js-facets-checkbox-links', context)
23      .once('facets-checkbox-transform');
24
25    if ($checkboxWidgets.length > 0) {
26      $checkboxWidgets.each(function (index, widget) {
27        var $widget = $(widget);
28        var $widgetLinks = $widget.find('.facet-item > a');
29
30        // Add correct CSS selector for the widget. The Facets JS API will
31        // register handlers on that element.
32        $widget.addClass('js-facets-widget');
33
34        // Transform links to checkboxes.
35        $widgetLinks.each(Drupal.facets.makeCheckbox);
36
37        // We have to trigger attaching of behaviours, so that Facets JS API can
38        // register handlers on checkbox widgets.
39        Drupal.attachBehaviors(this.parentNode, Drupal.settings);
40      });
41
42    }
43
44    // Set indeterminate value on parents having an active trail.
45    $('.facet-item--expanded.facet-item--active-trail > input').prop('indeterminate', true);
46  };
47
48  /**
49   * Replace a link with a checked checkbox.
50   */
51  Drupal.facets.makeCheckbox = function () {
52    var $link = $(this);
53    var active = $link.hasClass('is-active');
54    var description = $link.html();
55    var href = $link.attr('href');
56    var id = $link.data('drupal-facet-item-id');
57
58    var checkbox = $('<input type="checkbox" class="facets-checkbox">')
59      .attr('id', id)
60      .data($link.data())
61      .data('facetsredir', href);
62    var label = $('<label for="' + id + '" class="option checkbox-title">' + description + '</label>');
63
64    checkbox.on('change.facets', function (e) {
65      e.preventDefault();
66
67      var $widget = $(this).closest('.js-facets-widget');
68
69      Drupal.facets.disableFacet($widget);
70      $widget.trigger('facets_filter', [ href ]);
71    });
72
73    if (active) {
74      checkbox.attr('checked', true);
75      label.find('.js-facet-deactivate').remove();
76    }
77
78    $link.before(checkbox).before(label).hide();
79
80  };
81
82  /**
83   * Disable all facet checkboxes in the facet and apply a 'disabled' class.
84   *
85   * @param {object} $facet
86   *   jQuery object of the facet.
87   */
88  Drupal.facets.disableFacet = function ($facet) {
89    $facet.addClass('facets-disabled');
90    $('input.facets-checkbox', $facet).click(Drupal.facets.preventDefault);
91    $('input.facets-checkbox', $facet).attr('disabled', true);
92  };
93
94  /**
95   * Event listener for easy prevention of event propagation.
96   *
97   * @param {object} e
98   *   Event.
99   */
100  Drupal.facets.preventDefault = function (e) {
101    e.preventDefault();
102  };
103
104})(jQuery, Drupal);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.