PageSourceSearch

https://equicted.de/modules/better_exposed_filters/js/bef_select_all_none.js?v=3.x

js equicted.de collected 2026-10-05 03:57:41 UTC 5,260 bytes, 137 lines download raw bytes

1/**
2 * @file bef_select_all_none.js
3 *
4 * Adds select all/none toggle functionality to an exposed filter.
5 */
6(function ($) {
7  Drupal.behaviors.betterExposedFiltersSelectAllNone = {
8    attach: function (context) {
9      /*
10       * Add Select all/none links to specified checkboxes
11       */
12      var selected = $('.form-checkboxes.bef-select-all-none:not(.bef-processed)');
13      if (selected.length) {
14        var selAll = Drupal.t('Select All');
15        var selNone = Drupal.t('Select None');
16
17        // Set up a prototype link and event handlers
18        var link = $('<a class="bef-toggle" href="#">' + selAll + '</a>')
19        link.click(function (event) {
20          // Don't actually follow the link...
21          event.preventDefault();
22          event.stopPropagation();
23
24          if (selAll == $(this).text()) {
25            // Select all the checkboxes
26            $(this)
27              .html(selNone)
28              .siblings('.bef-select-all-none, .bef-tree')
29              .find('input:checkbox').each(function () {
30                $(this).prop('checked', true);
31                // @TODO:
32                //_bef_highlight(this, context);
33              })
34              .end()
35
36              // attr() doesn't trigger a change event, so we do it ourselves. But just on
37              // one checkbox otherwise we have many spinning cursors
38              .find('input[type=checkbox]:first').change()
39            ;
40          }
41          else {
42            // Unselect all the checkboxes
43            $(this)
44              .html(selAll)
45              .siblings('.bef-select-all-none, .bef-tree')
46              .find('input:checkbox').each(function () {
47                $(this).prop('checked', false);
48                // @TODO:
49                //_bef_highlight(this, context);
50              })
51              .end()
52
53              // attr() doesn't trigger a change event, so we do it ourselves. But just on
54              // one checkbox otherwise we have many spinning cursors
55              .find('input[type=checkbox]:first').change()
56            ;
57          }
58        });
59
60        // Add link to the page for each set of checkboxes.
61        selected
62          .addClass('bef-processed')
63          .each(function (index) {
64            // Clone the link prototype and insert into the DOM
65            var newLink = link.clone(true);
66
67            newLink.insertBefore($(this));
68
69            // If all checkboxes are already checked by default then switch to Select None
70            if ($('input:checkbox:checked', this).length == $('input:checkbox', this).length) {
71              newLink.text(selNone);
72            }
73          })
74        ;
75      }
76
77      // @TODO:
78      // Add highlight class to checked checkboxes for better theming
79      //$('.bef-tree input[type="checkbox"], .bef-checkboxes input[type="checkbox"]')
80      //// Highlight newly selected checkboxes
81      //  .change(function () {
82      //    _bef_highlight(this, context);
83      //  })
84      //  .filter(':checked').closest('.form-item', context).addClass('highlight')
85      //;
86
87      // @TODO: Put this somewhere else...
88      // Check for and initialize datepickers
89      //if (Drupal.settings.better_exposed_filters.datepicker) {
90      //  // Note: JavaScript does not treat "" as null
91      //  if (Drupal.settings.better_exposed_filters.datepicker_options.dateformat) {
92      //    $('.bef-datepicker').datepicker({
93      //      dateFormat: Drupal.settings.better_exposed_filters.datepicker_options.dateformat
94      //    });
95      //  }
96      //  else {
97      //    $('.bef-datepicker').datepicker();
98      //  }
99      //}
100
101    }                   // attach: function() {
102  };                    // Drupal.behaviors.better_exposed_filters = {
103
104  Drupal.behaviors.betterExposedFiltersAllNoneNested = {
105    attach:function (context, settings) {
106      $('.bef-select-all-none-nested li').has('ul').once('bef-all-none-nested').each(function () {
107        var $this = $(this);
108        // Check/uncheck child terms along with their parent.
109        $this.find('input:checkbox:first').change(function() {
110          $(this).closest('li').find('ul li input:checkbox').prop('checked', this.checked);
111        });
112
113        // When a child term is checked or unchecked, set the parent term's
114        // status as needed.
115        $this.find('ul input:checkbox').change(function() {
116          // Determine the number of unchecked sibling checkboxes.
117          var $this = $(this);
118          var uncheckedSiblings = $this.closest('li').siblings('li').find('> div > input:checkbox:not(:checked)').size();
119
120          // If this term or any siblings are unchecked, uncheck the parent and
121          // all ancestors.
122          if (uncheckedSiblings || !this.checked) {
123            $this.parents('ul').siblings('div').find('input:checkbox').prop('checked', false);
124          }
125
126          // If this and all sibling terms are checked, check the parent. Then
127          // trigger the parent's change event to see if that change affects the
128          // grandparent's checked state.
129          if (this.checked && !uncheckedSiblings) {
130            $(this).closest('ul').closest('li').find('input:checkbox:first').prop('checked', true).change();
131          }
132        });
133      });
134    }
135  }
136
137}) (jQuery);

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.