diff options
author | gemmaro <[email protected]> | 2022-09-24 23:29:51 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-07-05 03:37:28 +0000 |
commit | 77fa4787bd26b5193a5cc72226c1a3469f91ba11 (patch) | |
tree | 0189fb8ab398a1c6217880e85b735f6b2b7797d6 /lib/rdoc | |
parent | fd6da40fef5c6b818564ed0bc47672d1e069039c (diff) |
[ruby/rdoc] Add keydown event listener to focus on search field
https://github.com/ruby/rdoc/commit/db62e47df2
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml | 2 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/js/darkfish.js | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml index 9c49b31376..afc7f7b88d 100644 --- a/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +++ b/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml @@ -3,7 +3,7 @@ <div id="search-field-wrapper"> <input id="search-field" role="combobox" aria-label="Search" aria-autocomplete="list" aria-controls="search-results" - type="text" name="search" placeholder="Search" spellcheck="false" + type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false" title="Type to search, Up and Down to navigate, Enter to load"> </div> diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js index d0c9467751..19a85c54e1 100644 --- a/lib/rdoc/generator/template/darkfish/js/darkfish.js +++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js @@ -78,7 +78,20 @@ function hookSearch() { search.scrollIntoView = search.scrollInWindow; }; +function hookFocus() { + document.addEventListener("keydown", (event) => { + if (document.activeElement.tagName === 'INPUT') { + return; + } + if (event.key === "/") { + event.preventDefault(); + document.querySelector('#search-field').focus(); + } + }); +} + document.addEventListener('DOMContentLoaded', function() { hookSourceViews(); hookSearch(); + hookFocus(); }); |