aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-19 22:03:26 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-02 19:49:52 -0400
commita628610cbd9ea235987cef399021b0685c50f0e4 (patch)
tree841db884a997c6600f66e2de438cdf27f9ca8d3b /ext/fg/js
parentfba2bef90522dcfb084af57c9fae5d59c0f7f033 (diff)
Use KeyboardEvent.key for onKeyDown handlers
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/float.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 2e952efb..8a05aa70 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -102,21 +102,16 @@ class DisplayFloat extends Display {
}
onKeyDown(e) {
- const handlers = {
- 67: /* c */ () => {
- if (e.ctrlKey && !window.getSelection().toString()) {
- this.onSelectionCopy();
- return true;
- }
+ const key = Display.getKeyFromEvent(e);
+ const handlers = DisplayFloat.onKeyDownHandlers;
+ if (handlers.hasOwnProperty(key)) {
+ const handler = handlers[key];
+ if (handler(this, e)) {
+ e.preventDefault();
+ return;
}
- };
-
- const handler = handlers[e.keyCode];
- if (handler && handler()) {
- e.preventDefault();
- } else {
- super.onKeyDown(e);
}
+ super.onKeyDown(e);
}
autoPlayAudio() {
@@ -146,4 +141,14 @@ class DisplayFloat extends Display {
}
}
+DisplayFloat.onKeyDownHandlers = {
+ 'C': (self, e) => {
+ if (e.ctrlKey && !window.getSelection().toString()) {
+ self.onSelectionCopy();
+ return true;
+ }
+ return false;
+ }
+};
+
window.yomichan_display = new DisplayFloat();