2021-04-07 08:37:11 +00:00
|
|
|
|
2021-04-05 14:16:05 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2021-04-07 08:37:11 +00:00
|
|
|
/**
|
|
|
|
* Toggle all descendant checkboxes of a target.
|
|
|
|
*
|
|
|
|
* Use `data-target="ID_OF_TARGET"` on the node on which the event is listened
|
|
|
|
* to (checkbox, button, link…), where_ID_OF_TARGET_ should be the ID of an
|
|
|
|
* ancestor for the checkboxes.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* <input
|
|
|
|
* type="checkbox"
|
|
|
|
* data-action="toggle-all"
|
|
|
|
* data-target="failed-imports"
|
|
|
|
* >
|
|
|
|
* @param {Event} event
|
|
|
|
* @return {undefined}
|
|
|
|
*/
|
2021-04-05 14:16:05 +00:00
|
|
|
function toggleAllCheckboxes(event) {
|
|
|
|
const mainCheckbox = event.target;
|
|
|
|
|
|
|
|
document
|
|
|
|
.querySelectorAll(`#${mainCheckbox.dataset.target} [type="checkbox"]`)
|
2021-04-06 07:11:56 +00:00
|
|
|
.forEach(checkbox => checkbox.checked = mainCheckbox.checked);
|
2021-04-05 14:16:05 +00:00
|
|
|
}
|
2021-03-19 17:51:45 +00:00
|
|
|
|
|
|
|
document
|
2021-04-05 14:16:05 +00:00
|
|
|
.querySelectorAll('[data-action="toggle-all"]')
|
|
|
|
.forEach(input => {
|
|
|
|
input.addEventListener('change', toggleAllCheckboxes);
|
|
|
|
});
|
|
|
|
})();
|