aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fn/fn.js29
-rw-r--r--src/home.js21
-rw-r--r--src/media.js18
3 files changed, 41 insertions, 27 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
*/
diff --git a/src/home.js b/src/home.js
index 0778edb..a75ba1d 100644
--- a/src/home.js
+++ b/src/home.js
@@ -1,18 +1,11 @@
-import { checkallHandler, closeSubmenus, activateSelectAll } from './fn/fn';
+import {
+ activateCheckall,
+ activateCloseSubmenus,
+ activateSelectAll,
+} from './fn/fn';
window.addEventListener('load', () => {
- let checkboxes = document.getElementsByName('pagesid[]');
- let checkall = document.getElementById('checkall');
- if (!checkall) {
- return;
- }
- let checkbox = document.createElement('input');
- checkbox.type = 'checkbox';
- checkbox.addEventListener('input', checkallHandler.bind({ checkboxes }));
- checkall.innerHTML = '';
- checkall.appendChild(checkbox);
-
+ activateCheckall('pagesid[]', 'checkall');
activateSelectAll();
+ activateCloseSubmenus();
});
-
-window.addEventListener('click', closeSubmenus);
diff --git a/src/media.js b/src/media.js
index 356c7c9..1073d23 100644
--- a/src/media.js
+++ b/src/media.js
@@ -1,15 +1,11 @@
-import { checkallHandler, closeSubmenus, activateSelectAll } from './fn/fn';
+import {
+ activateCheckall,
+ activateCloseSubmenus,
+ activateSelectAll,
+} from './fn/fn';
window.addEventListener('load', () => {
- let checkboxes = document.getElementsByName('id[]');
- let checkall = document.getElementById('checkall');
- let checkbox = document.createElement('input');
- checkbox.type = 'checkbox';
- checkbox.addEventListener('input', checkallHandler.bind({ checkboxes }));
- checkall.innerHTML = '';
- checkall.appendChild(checkbox);
-
+ activateCheckall('id[]', 'checkall');
activateSelectAll();
+ activateCloseSubmenus();
});
-
-window.addEventListener('click', closeSubmenus);