aboutsummaryrefslogtreecommitdiff
path: root/src/fn/fn.js
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2020-04-28 18:08:35 +0200
committern-peugnet <n.peugnet@free.fr>2020-04-28 18:08:35 +0200
commit5b1457835be6c00a7d108537ecc88d3d85d48d51 (patch)
tree5db70e04ce18ba9b15bdd69e85e8e483585e13ae /src/fn/fn.js
parent877e0570ea7eb94e9698aab9147104f5251f55c9 (diff)
downloadwcms-5b1457835be6c00a7d108537ecc88d3d85d48d51.tar.gz
wcms-5b1457835be6c00a7d108537ecc88d3d85d48d51.zip
feat: select all for code inputs
This enable the "select all" feature for `input.select-all` element. input elements are used because these are the only one with the `select()` method. To obtain the same rendering as before the readonly attribute and the class `code` have been added to these elements. @vincent-peugnet: make sure to use this element for future select-all Closes #107
Diffstat (limited to 'src/fn/fn.js')
-rw-r--r--src/fn/fn.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/fn/fn.js b/src/fn/fn.js
index bca4eaf..a5aa538 100644
--- a/src/fn/fn.js
+++ b/src/fn/fn.js
@@ -28,3 +28,24 @@ export function closeSubmenus(e) {
}
}
}
+
+/**
+ * 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);
+ }
+}