summaryrefslogtreecommitdiff
path: root/lib/rdoc/generator/template/darkfish/js/darkfish.js
diff options
context:
space:
mode:
authorgemmaro <gemmaro.dev@gmail.com>2022-09-24 23:29:51 +0900
committergit <svn-admin@ruby-lang.org>2023-07-05 03:37:28 +0000
commit77fa4787bd26b5193a5cc72226c1a3469f91ba11 (patch)
tree0189fb8ab398a1c6217880e85b735f6b2b7797d6 /lib/rdoc/generator/template/darkfish/js/darkfish.js
parentfd6da40fef5c6b818564ed0bc47672d1e069039c (diff)
[ruby/rdoc] Add keydown event listener to focus on search field
https://github.com/ruby/rdoc/commit/db62e47df2
Diffstat (limited to 'lib/rdoc/generator/template/darkfish/js/darkfish.js')
-rw-r--r--lib/rdoc/generator/template/darkfish/js/darkfish.js13
1 files changed, 13 insertions, 0 deletions
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();
});