diff options
| author | bors <bors@rust-lang.org> | 2020-12-01 09:58:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-12-01 09:58:59 +0000 |
| commit | 0fa9d31c41cfa5f60dbce1204104eb8d8261be5f (patch) | |
| tree | fad5578bd03825f08b8e0d8ac4bffce1d28c9050 /src/librustdoc/html/static/main.js | |
| parent | c4926d01ada661d4fbffb0e5b1708ae5463d47b3 (diff) | |
| parent | 14ecee769318615b6497957d225c8869d07f3e97 (diff) | |
| download | rust-0fa9d31c41cfa5f60dbce1204104eb8d8261be5f.tar.gz rust-0fa9d31c41cfa5f60dbce1204104eb8d8261be5f.zip | |
Auto merge of #78876 - GuillaumeGomez:better-setting-keyboard-ux, r=jyn514
Make keyboard interactions in the settings menu more pleasant #78868 improved the keyboard interactions with the settings page. This PR goes a bit further by allowing more than just "space" to toggle the checkboxes. r? `@jyn514`
Diffstat (limited to 'src/librustdoc/html/static/main.js')
| -rw-r--r-- | src/librustdoc/html/static/main.js | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 7ca43684dce..69984be5eb6 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -40,6 +40,29 @@ if (!DOMTokenList.prototype.remove) { }; } + +// Gets the human-readable string for the virtual-key code of the +// given KeyboardEvent, ev. +// +// This function is meant as a polyfill for KeyboardEvent#key, +// since it is not supported in IE 11 or Chrome for Android. We also test for +// KeyboardEvent#keyCode because the handleShortcut handler is +// also registered for the keydown event, because Blink doesn't fire +// keypress on hitting the Escape key. +// +// So I guess you could say things are getting pretty interoperable. +function getVirtualKey(ev) { + if ("key" in ev && typeof ev.key != "undefined") { + return ev.key; + } + + var c = ev.charCode || ev.keyCode; + if (c == 27) { + return "Escape"; + } + return String.fromCharCode(c); +} + function getSearchInput() { return document.getElementsByClassName("search-input")[0]; } @@ -326,28 +349,6 @@ function defocusSearchBar() { } } - // Gets the human-readable string for the virtual-key code of the - // given KeyboardEvent, ev. - // - // This function is meant as a polyfill for KeyboardEvent#key, - // since it is not supported in Trident. We also test for - // KeyboardEvent#keyCode because the handleShortcut handler is - // also registered for the keydown event, because Blink doesn't fire - // keypress on hitting the Escape key. - // - // So I guess you could say things are getting pretty interoperable. - function getVirtualKey(ev) { - if ("key" in ev && typeof ev.key != "undefined") { - return ev.key; - } - - var c = ev.charCode || ev.keyCode; - if (c == 27) { - return "Escape"; - } - return String.fromCharCode(c); - } - function getHelpElement() { buildHelperPopup(); return document.getElementById("help"); |
