help.html: implement "/" for making search box active.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 25 Sep 2022 17:35:40 +0000 (10:35 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 25 Sep 2022 17:36:00 +0000 (10:36 -0700)
basis/help/html/html.factor
extra/webapps/help/search.js

index d179b3ef3ac402be630b87d165cf67a007c65a43..4cd0f8c889da55ad40ea890a9f3b1dd952f45038 100644 (file)
@@ -91,12 +91,31 @@ M: pathname url-of
         />
     XML] ;
 
+: help-script ( -- xml )
+    [XML
+        <script type="text/javascript">
+        document.addEventListener('keydown', function (event) {
+            if (event.code == 'Slash') {
+                let input = document.getElementById('search');
+                if (input !== document.activeElement) {
+                    setTimeout(function() {
+                        input.focus().select()
+                    }, 0);
+                }
+            }
+        });
+        </script>
+     XML] ;
+
+: help-header ( stylesheet -- xml )
+    help-stylesheet help-meta swap help-script 3append ;
+
 : help-nav ( -- xml )
     "conventions" >link topic>filename
     [XML
         <nav>
             <form method="get" action="/search" style="float: right;">
-                <input placeholder="Search" name="search" type="text" tabindex="1" />
+                <input placeholder="Search" id="search" name="search" type="text" tabindex="1" />
                 <input type="submit" value="Go" tabindex="1" />
             </form>
             <a href="https://factorcode.org">
@@ -250,7 +269,7 @@ M: pathname url-of
         [ print-topic ] with-html-writer
         css-styles-to-classes cache-images
         "resource:extra/websites/factorcode/favicon.ico" dup file-name ?copy-file
-        [ help-stylesheet help-meta prepend help-nav ] dip help-footer
+        [ help-header help-nav ] dip help-footer
         [XML <-><div class="page"><-><-></div> XML]
     ] bi simple-page ;
 
index 674a7bcc9abd4fd0dc28cfd073d5a063213a5c96..b48c5771bb27507009c4c25c6ba39b4e712912bb 100644 (file)
@@ -4,3 +4,14 @@ window.onload = function() {
         radios[0].checked = true;
     }
 }
+
+document.addEventListener('keydown', function (event) {
+    if (event.code == 'Slash') {
+        let input = document.getElementById('search');
+        if (input !== document.activeElement) {
+            setTimeout(function() {
+                input.focus().select()
+            }, 0);
+        }
+    }
+});