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