aboutsummaryrefslogtreecommitdiff
path: root/src/home.js
blob: 670ae3e6be2d387dfc12dbc05f608c6a090ac351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/** @type {HTMLInputElement[]} */
let checkboxes = [];

window.addEventListener('load', () => {
    checkboxes = document.getElementsByName('pagesid[]');
    let checkall = document.getElementById('checkall');
    let checkbox = document.createElement('input');
    checkbox.type = 'checkbox';
    checkbox.addEventListener('input', checkallHandler);
    checkall.innerHTML = '';
    checkall.appendChild(checkbox);
});

/**
 * Manage input event on the checkall checkbox.
 * @param {InputEvent} e the input event
 */
function checkallHandler(e) {
    if (e.target.checked) {
        for (const checkbox of checkboxes) {
            checkbox.checked = true;
        }
    } else {
        for (const checkbox of checkboxes) {
            checkbox.checked = false;
        }
    }
}