Move check all js into separate file
This commit is contained in:
parent
443daab128
commit
5ad645c225
3 changed files with 28 additions and 23 deletions
24
bookwyrm/static/js/check_all.js
Normal file
24
bookwyrm/static/js/check_all.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Toggle all checkboxes.
|
||||
window.onload = function() {
|
||||
document
|
||||
.querySelectorAll('[data-action="toggle-all"]')
|
||||
.forEach(input => {
|
||||
input.addEventListener('change', 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}
|
||||
*/
|
||||
function toggleAllCheckboxes(event) {
|
||||
const mainCheckbox = event.target;
|
||||
|
||||
document
|
||||
.querySelectorAll(`#${mainCheckbox.dataset.target} [type="checkbox"]`)
|
||||
.forEach(checkbox => {checkbox.checked = mainCheckbox.checked;});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue