word/edit: search button toggles empty input
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 6 Jan 2022 18:23:29 +0000 (19:23 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 7 Feb 2022 17:42:33 +0000 (18:42 +0100)
Minimal javascript to make hiding work as expected.

word/editor.js

index aeab4cc70bd6d14ecde326d4a40fd972bd5d2f07..0e54c62fe349a571727d1266af945bf12bddcbc2 100644 (file)
@@ -1,4 +1,17 @@
 document.addEventListener('DOMContentLoaded', () => {
+       document.querySelectorAll('#search').forEach(p => {
+               let [input, button] = p.children;
+               button.onclick = e => {
+                       if (input.value && input.offsetWidth > 50) {
+                               return true; // bubble to submit
+                       }
+                       // make visible first
+                       input.focus();
+                       e.preventDefault();
+                       return false;
+               };
+       });
+
        document.querySelectorAll('.multiinput > input[id]').forEach(el => {
                el.oninput = e => {
                        if (e.target.value == '') return;