1/** 2 * @file 3 * better_exposed_filters.js 4 * 5 * Provides some client-side functionality for the Better Exposed Filters module. 6 */ 7 8(function ($, Drupal, once) { 9 Drupal.behaviors.betterExposedFilters = { 10 attach: function (context) { 11 // Add highlight class to checked checkboxes for better theming. 12 $('.bef-tree input[type=checkbox], .bef-checkboxes input[type=checkbox]') 13 // Highlight newly selected checkboxes. 14 .change(function () { 15 _bef_highlight(this, context); 16 }) 17 .filter(':checked').closest('.form-item', context).addClass('highlight'); 18 } 19 }; 20 21 /* 22 * Helper functions 23 */ 24 25 /** 26 * Adds/Removes the highlight class from the form-item div as appropriate. 27 */ 28 function _bef_highlight(elem, context) { 29 $elem = $(elem, context); 30 $elem.attr('checked') 31 ? $elem.closest('.form-item', context).addClass('highlight') 32 : $elem.closest('.form-item', context).removeClass('highlight'); 33 } 34 35 /** 36 * Adds the data-bef-auto-submit-exclude to elements with type="text". 37 */ 38 Drupal.behaviors.autosubmitExcludeTextfield = { 39 attach: function (context, settings) { 40 if (!settings.better_exposed_filters?.autosubmit_exclude_textfield) { 41 return; 42 } 43 $(once('autosubmit-exclude-textfield', '.bef-exposed-form', context)).each(function () { 44 $(this).find('*[type="text"]').attr('data-bef-auto-submit-exclude', ''); 45 }); 46 } 47 }; 48 49 /** 50 * Fix duplicate parameters from being passed. 51 */ 52 Drupal.behaviors.befSingleCheckboxFix = { 53 attach: function (context, settings) { 54 once('befSingleCheckboxFix', 'form.views-exposed-form', context).forEach((form) => { 55 const $form = $(form); 56 const $checkboxes = $form.find('input[type="checkbox"].single-checkbox'); 57 58 $form.on('submit', function () { 59 // For each checkbox, handle the hidden input fallback. 60 $checkboxes.each(function () { 61 const $checkbox = $(this); 62 const name = $checkbox.attr('name'); 63 64 // Remove any existing hidden inputs with this name to avoid duplicates. 65 $form.find('input[type="hidden"][name="' + name + '"]').remove(); 66 67 if (!$checkbox.is(':checked')) { 68 // Add hidden input only when checkbox is unchecked. 69 $('<input>').attr({ 70 type: 'hidden', 71 name: name, 72 value: 0, 73 }).appendTo($form); 74 } 75 }); 76 }); 77 }); 78 } 79 }; 80 81})(jQuery, Drupal, once);
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.