Rollup merge of #49152 - GuillaumeGomez:rustdoc-event-handling, r=QuietMisdreavus

Fix events handling in rustdoc

Fixes #49075.
This commit is contained in:
kennytm 2018-03-20 07:15:28 +08:00
commit 45de057727
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C

View File

@ -239,52 +239,59 @@
} }
} }
function handleShortcut(ev) { function handleEscape(ev, help) {
if (document.activeElement.tagName === "INPUT" && hideModal();
hasClass(document.getElementById('main'), "hidden")) { var search = document.getElementById("search");
return; if (!hasClass(help, "hidden")) {
displayHelp(false, ev);
} else if (!hasClass(search, "hidden")) {
ev.preventDefault();
addClass(search, "hidden");
removeClass(document.getElementById("main"), "hidden");
} }
defocusSearchBar();
}
function handleShortcut(ev) {
// Don't interfere with browser shortcuts // Don't interfere with browser shortcuts
if (ev.ctrlKey || ev.altKey || ev.metaKey) { if (ev.ctrlKey || ev.altKey || ev.metaKey) {
return; return;
} }
var help = document.getElementById("help"); var help = document.getElementById("help");
switch (getVirtualKey(ev)) { if (document.activeElement.tagName === "INPUT") {
case "Escape": switch (getVirtualKey(ev)) {
hideModal(); case "Escape":
var search = document.getElementById("search"); handleEscape(ev, help);
if (!hasClass(help, "hidden")) { break;
}
} else {
switch (getVirtualKey(ev)) {
case "Escape":
handleEscape(ev, help);
break;
case "s":
case "S":
displayHelp(false, ev); displayHelp(false, ev);
} else if (!hasClass(search, "hidden")) {
ev.preventDefault();
addClass(search, "hidden");
removeClass(document.getElementById("main"), "hidden");
}
defocusSearchBar();
break;
case "s":
case "S":
displayHelp(false, ev);
hideModal();
ev.preventDefault();
focusSearchBar();
break;
case "+":
case "-":
ev.preventDefault();
toggleAllDocs();
break;
case "?":
if (ev.shiftKey) {
hideModal(); hideModal();
displayHelp(true, ev); ev.preventDefault();
focusSearchBar();
break;
case "+":
case "-":
ev.preventDefault();
toggleAllDocs();
break;
case "?":
if (ev.shiftKey) {
hideModal();
displayHelp(true, ev);
}
break;
} }
break;
} }
} }