From 6f74cb8b29c2e506be3188bda391219e74736887 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 18 Apr 2017 21:56:32 +0300 Subject: [PATCH] event.keyCode doesn't work in Firefox --- edit.js | 4 +++- manage.js | 2 +- msgbox/msgbox.js | 5 +++-- popup.js | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/edit.js b/edit.js index 99308bd4..ae41418a 100644 --- a/edit.js +++ b/edit.js @@ -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); diff --git a/manage.js b/manage.js index 164656c9..97b6f4eb 100644 --- a/manage.js +++ b/manage.js @@ -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(); diff --git a/msgbox/msgbox.js b/msgbox/msgbox.js index 46807b1b..640add2e 100644 --- a/msgbox/msgbox.js +++ b/msgbox/msgbox.js @@ -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() { diff --git a/popup.js b/popup.js index 813bbd62..28a2d3ac 100644 --- a/popup.js +++ b/popup.js @@ -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) {