event.keyCode doesn't work in Firefox

This commit is contained in:
tophf 2017-04-18 21:56:32 +03:00
parent a2943852a7
commit 6f74cb8b29
4 changed files with 10 additions and 6 deletions

View File

@ -1783,7 +1783,9 @@ function showHelp(title, text) {
return div;
function closeHelp(e) {
if (!e || e.type == "click" || (e.keyCode == 27 && !e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey)) {
if (!e
|| e.type == "click"
|| ((e.keyCode || e.which) == 27 && !e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey)) {
div.style.display = "";
document.querySelector(".contents").innerHTML = "";
document.removeEventListener("keydown", closeHelp);

View File

@ -59,7 +59,7 @@ function initGlobalEvents() {
// focus search field on / key
document.onkeypress = event => {
if (event.keyCode == 47
if ((event.keyCode || event.which) == 47
&& !event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey
&& !event.target.matches('[type="text"], [type="search"]')) {
event.preventDefault();

View File

@ -28,10 +28,11 @@ function messageBox({
resolveWith({button: this.buttonIndex});
},
key(event) {
const keyCode = event.keyCode || event.which;
if (!event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey
&& (event.keyCode == 13 || event.keyCode == 27)) {
&& (keyCode == 13 || keyCode == 27)) {
event.preventDefault();
resolveWith(event.keyCode == 13 ? {enter: true} : {esc: true});
resolveWith(keyCode == 13 ? {enter: true} : {esc: true});
}
},
scroll() {

View File

@ -275,10 +275,11 @@ Object.assign(handleEvent, {
$('[data-cmd="ok"]', box).onclick = () => confirm(true);
$('[data-cmd="cancel"]', box).onclick = () => confirm(false);
window.onkeydown = event => {
const keyCode = event.keyCode || event.which;
if (!event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey
&& (event.keyCode == 13 || event.keyCode == 27)) {
&& (keyCode == 13 || keyCode == 27)) {
event.preventDefault();
confirm(event.keyCode == 13);
confirm(keyCode == 13);
}
};
function confirm(ok) {