diff --git a/bookwyrm/static/js/check_all.js b/bookwyrm/static/js/check_all.js index 07d30a686..72c83e3e9 100644 --- a/bookwyrm/static/js/check_all.js +++ b/bookwyrm/static/js/check_all.js @@ -1,17 +1,24 @@ -/* exported toggleAllCheckboxes */ - /** * Toggle all descendant checkboxes of a target. * - * Use `data-target="ID_OF_TARGET"` on the node being listened to. - * - * @param {Event} event - change Event - * @return {undefined} + * 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. */ -function toggleAllCheckboxes(event) { - const mainCheckbox = event.target; +(function() { + 'use strict'; + + function toggleAllCheckboxes(event) { + const mainCheckbox = event.target; + + document + .querySelectorAll(`#${mainCheckbox.dataset.target} [type="checkbox"]`) + .forEach(checkbox => {checkbox.checked = mainCheckbox.checked;}); + } document - .querySelectorAll(`#${mainCheckbox.dataset.target} [type="checkbox"]`) - .forEach(checkbox => {checkbox.checked = mainCheckbox.checked;}); -} + .querySelectorAll('[data-action="toggle-all"]') + .forEach(input => { + input.addEventListener('change', toggleAllCheckboxes); + }); +})(); diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index 7a198619c..5ca3d7d7a 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -1,4 +1,4 @@ -/* globals setDisplay TabGroup toggleAllCheckboxes updateDisplay */ +/* globals setDisplay TabGroup updateDisplay */ // set up javascript listeners window.onload = function() { @@ -36,13 +36,6 @@ window.onload = function() { // update localstorage Array.from(document.getElementsByClassName('set-display')) .forEach(t => t.onclick = updateDisplay); - - // Toggle all checkboxes. - document - .querySelectorAll('[data-action="toggle-all"]') - .forEach(input => { - input.addEventListener('change', toggleAllCheckboxes); - }); }; function back(e) {