This commit is contained in:
Alex Yatskov 2017-03-18 18:08:09 -07:00
parent ad313fd182
commit 1a4c94209b

View File

@ -80,7 +80,7 @@ class Display {
$('.action-play-audio').click(e => { $('.action-play-audio').click(e => {
e.preventDefault(); e.preventDefault();
const index = Display.entryIndexFind($(e.currentTarget)); const index = Display.entryIndexFind($(e.currentTarget));
Display.audioPlay(this.definitions[index], this.audioCache); this.audioPlay(this.definitions[index]);
}); });
$('.kanji-link').click(e => { $('.kanji-link').click(e => {
e.preventDefault(); e.preventDefault();
@ -209,24 +209,46 @@ class Display {
} }
onKeyDown(e) { onKeyDown(e) {
if (e.keyCode === 36 /* home */) { const handlers = {
e.preventDefault(); 36: /* home */ () => {
this.entryScroll(0, true); this.entryScroll(0, true);
} else if (e.keyCode === 35 /* end */) { },
e.preventDefault();
35: /* end */ () => {
this.entryScroll(this.definitions.length - 1, true); this.entryScroll(this.definitions.length - 1, true);
} if (e.keyCode === 38 /* up */) { },
e.preventDefault();
38: /* up */ () => {
this.entryScroll(this.index - 1, true); this.entryScroll(this.index - 1, true);
} else if (e.keyCode === 40 /* down */) { },
e.preventDefault();
40: /* down */ () => {
this.entryScroll(this.index + 1, true); this.entryScroll(this.index + 1, true);
},
209: /* [ */ () => {
},
221: /* ] */ () => {
},
220: /* \ */ () => {
this.audioPlay(this.definitions[this.index]);
}
};
const handler = handlers[e.keyCode];
if (handler) {
e.preventDefault();
handler();
} }
} }
static audioPlay(definition, cache) { audioPlay(definition) {
for (const key in cache) { for (const key in this.audioCache) {
const audio = cache[key]; const audio = this.audioCache[key];
if (audio !== null) { if (audio !== null) {
audio.pause(); audio.pause();
} }
@ -237,7 +259,7 @@ class Display {
return; return;
} }
let audio = cache[url]; let audio = this.audioCache[url];
if (audio) { if (audio) {
audio.currentTime = 0; audio.currentTime = 0;
audio.play(); audio.play();
@ -248,7 +270,7 @@ class Display {
audio = new Audio('/mixed/mp3/button.mp3'); audio = new Audio('/mixed/mp3/button.mp3');
} }
cache[url] = audio; this.audioCache[url] = audio;
audio.play(); audio.play();
}; };
} }