Skip to content
Snippets Groups Projects

Issue #3197651: Select / Unselect All taxonomies, blocks, or menus

Files
5
+ 43
0
/**
* @file
* function to select and unselect all entities.
*/
(function (Drupal, $, once) {
'use strict';
/**
* Uncheck all checkboxes.
*
* @type {{attach: Drupal.behaviors.unselectAll.attach}}
*/
Drupal.behaviors.unselectAll = {
attach: function (context, settings) {
once('selectUnselectAll', '.form-checkboxes', context).forEach(function (checkboxes) {
// Set up a prototype link.
let selAll = Drupal.t('Select All'),
selNone = Drupal.t('Unselect All'),
link = $('<a class="select-unselect-all" href="#">' + selNone + '</a>');
$(checkboxes).prepend(link);
// Set an event handler.
link.click(function (event) {
// Don't follow the link.
event.preventDefault();
event.stopPropagation();
let check = $(this).text() === selAll;
$(this)
.html(check ? selNone : selAll)
.siblings('.form-type--checkbox')
.find('input:checkbox')
.prop('checked', check);
});
});
},
};
})(Drupal, jQuery, once);
Loading