зеркало из https://github.com/github/ruby.git
[ruby/rdoc] Add keydown event listener to focus on search field
https://github.com/ruby/rdoc/commit/db62e47df2
This commit is contained in:
Родитель
fd6da40fef
Коммит
77fa4787bd
|
@ -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>
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче