diff options
author | n-peugnet <n.peugnet@free.fr> | 2020-04-28 18:15:46 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2020-04-28 18:15:46 +0200 |
commit | 3183ce9dd42211b7279c7ce545c414452f5a9ef0 (patch) | |
tree | 445b0abaf9404a1449fa9f55d52fd42d49826642 /src/fn | |
parent | 5b1457835be6c00a7d108537ecc88d3d85d48d51 (diff) | |
download | wcms-3183ce9dd42211b7279c7ce545c414452f5a9ef0.tar.gz wcms-3183ce9dd42211b7279c7ce545c414452f5a9ef0.zip |
refactor: clean js code with "activate" functions
Diffstat (limited to 'src/fn')
-rw-r--r-- | src/fn/fn.js | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/fn/fn.js b/src/fn/fn.js index a5aa538..69cbe2a 100644 --- a/src/fn/fn.js +++ b/src/fn/fn.js @@ -3,7 +3,7 @@ * Call with .bind({checkboxes: HTMLElement[]}) * @param {InputEvent} e the input event */ -export function checkallHandler(e) { +function checkallHandler(e) { if (e.target.checked) { for (const checkbox of this.checkboxes) { checkbox.checked = true; @@ -16,10 +16,28 @@ export function checkallHandler(e) { } /** + * Activate the checkall feature + * @param {string} checkboxesName value of the name property of the desired checkbox elements. + * @param {string} checkallId value of the id property of the desired checkall element. + */ +export function activateCheckall(checkboxesName, checkallId) { + let checkboxes = document.getElementsByName(checkboxesName); + let checkall = document.getElementById(checkallId); + if (!checkall) { + return; + } + let checkbox = document.createElement('input'); + checkbox.type = 'checkbox'; + checkbox.addEventListener('input', checkallHandler.bind({ checkboxes })); + checkall.innerHTML = ''; + checkall.appendChild(checkbox); +} + +/** * Close all submenus of the menubar. * @param {MouseEvent} e */ -export function closeSubmenus(e) { +function closeSubmenus(e) { let details = document.querySelectorAll('aside details'); let currentDetail = e.target.closest('details'); for (const detail of details) { @@ -30,6 +48,13 @@ export function closeSubmenus(e) { } /** + * Activate "close submenus" feature on click anywhere. + */ +export function activateCloseSubmenus() { + window.addEventListener('click', closeSubmenus); +} + +/** * Select the whole content of the clicked item. * @param {MouseEvent} e */ |