summaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-25 17:53:25 -0700
committerAlex Yatskov <alex@foosoft.net>2017-03-25 17:53:25 -0700
commit2580dd8e7fc21bc5c39521f777a53c2aa790cfe1 (patch)
tree1344edf6965130fe55f56787d0c01a92812a149a /ext/mixed/js
parentf5a8383d2a670f32d5431150fe6571a3ada3bf18 (diff)
keyboard shortcuts
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/display.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index dca32e78..639c2673 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -211,7 +211,13 @@ class Display {
}
onKeyDown(e) {
- const requireAlt = ['e', 'k', 'p'];
+ const noteTryAdd = mode => {
+ const button = Display.adderButtonFind(this.index, mode);
+ if (button.length !== 0 && !button.hasClass('disabled')) {
+ this.noteAdd(this.definitions[this.index], mode);
+ }
+ };
+
const handlers = {
27: /* escape */ () => {
this.clearSearch();
@@ -242,20 +248,26 @@ class Display {
},
69: /* e */ () => {
- this.noteAdd(this.definitions[this.index], 'term-kanji');
+ noteTryAdd('term-kanji');
},
75: /* k */ () => {
- this.noteAdd(this.definitions[this.index], 'term-kana');
+ noteTryAdd('kanji');
+ },
+
+ 82: /* r */ () => {
+ noteTryAdd('term-kana');
},
80: /* p */ () => {
- this.audioPlay(this.definitions[this.index]);
+ if (Display.adderButtonFind(this.index, 'kanji').length === 0) {
+ this.audioPlay(this.definitions[this.index]);
+ }
}
};
const handler = handlers[e.keyCode];
- if (handler && (e.altKey || !requireAlt.includes(e.keyCode))) {
+ if (handler && (e.altKey || !['e', 'k', 'p'].includes(e.keyCode))) {
e.preventDefault();
handler();
}