aboutsummaryrefslogtreecommitdiff
path: root/static/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/index.js')
-rw-r--r--static/index.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/static/index.js b/static/index.js
new file mode 100644
index 0000000..291c256
--- /dev/null
+++ b/static/index.js
@@ -0,0 +1,25 @@
+/* Allow toggling the checkboxes with space, enter, and left/right */
+let myLabels = document.querySelectorAll('.lbl-toggle');
+Array.from(myLabels).forEach(label => {
+ label.addEventListener('keydown', e => {
+ // 32 spacebar, 13 enter
+ if (e.which === 32 || e.which === 13) {
+ e.preventDefault(); label.click();
+ };
+ // 37 left, 39 right
+ if (e.which === 37 || e.which === 39) {
+ var inputs = document.getElementsByTagName('INPUT');
+ for (var i=0; i < inputs.length; i++) {
+ if (inputs[i].id === e.target.htmlFor) {
+ if (!inputs[i].checked && e.which === 39) {
+ e.preventDefault(); label.click();
+ }
+ if (inputs[i].checked && e.which === 37) {
+ e.preventDefault(); label.click();
+ }
+ }
+ }
+ }
+ });
+});
+
bgstack15