aboutsummaryrefslogtreecommitdiff
path: root/src/fn/fn.js
blob: a5aa53898d99e85ae883736830abebda955011ed (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * Manage input event on the checkall checkbox.
 * Call with .bind({checkboxes: HTMLElement[]})
 * @param {InputEvent} e the input event
 */
export function checkallHandler(e) {
    if (e.target.checked) {
        for (const checkbox of this.checkboxes) {
            checkbox.checked = true;
        }
    } else {
        for (const checkbox of this.checkboxes) {
            checkbox.checked = false;
        }
    }
}

/**
 * Close all submenus of the menubar.
 * @param {MouseEvent} e
 */
export function closeSubmenus(e) {
    let details = document.querySelectorAll('aside details');
    let currentDetail = e.target.closest('details');
    for (const detail of details) {
        if (!detail.isSameNode(currentDetail)) {
            detail.removeAttribute('open');
        }
    }
}

/**
 * Select the whole content of the clicked item.
 * @param {MouseEvent} e
 */
function selectAll(e) {
    if (e.target instanceof HTMLInputElement) {
        e.target.select();
        e.target.focus();
    }
}

/**
 * Activate "select all" feature for `input.select-all` elements.
 */
export function activateSelectAll() {
    let selectAllInputs = document.querySelectorAll('input.select-all');
    for (const selectAllInput of selectAllInputs) {
        selectAllInput.addEventListener('click', selectAll);
    }
}