aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-15 14:06:27 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-27 21:40:59 -0400
commit355fb29c3b532da279a54114c5b4b976fce3ff20 (patch)
treef19cc0261fd6fabffad199c8d929c5ed8b762267
parentb61fc810127ae3cf54e6f4ca84ea95301f9ba2a5 (diff)
Use entryIndexFind without jQuery
-rw-r--r--ext/mixed/js/display.js42
1 files changed, 26 insertions, 16 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 3a728ee8..1ce997a1 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -52,11 +52,11 @@ class Display {
try {
e.preventDefault();
- const link = $(e.target);
+ const link = e.target;
const context = {
source: {
definitions: this.definitions,
- index: Display.entryIndexFind(link),
+ index: this.entryIndexFind(link),
scroll: $('html,body').scrollTop()
}
};
@@ -67,7 +67,7 @@ class Display {
context.source.source = this.context.source;
}
- const kanjiDefs = await apiKanjiFind(link.text(), this.optionsContext);
+ const kanjiDefs = await apiKanjiFind(link.textContent, this.optionsContext);
this.kanjiShow(kanjiDefs, this.options, context);
} catch (e) {
this.onError(e);
@@ -80,7 +80,7 @@ class Display {
const {docRangeFromPoint, docSentenceExtract} = this.dependencies;
- const clickedElement = $(e.target);
+ const clickedElement = e.target;
const textSource = docRangeFromPoint(e.clientX, e.clientY, this.options);
if (textSource === null) {
return false;
@@ -105,7 +105,7 @@ class Display {
const context = {
source: {
definitions: this.definitions,
- index: Display.entryIndexFind(clickedElement),
+ index: this.entryIndexFind(clickedElement),
scroll: $('html,body').scrollTop()
}
};
@@ -124,24 +124,24 @@ class Display {
onAudioPlay(e) {
e.preventDefault();
- const link = $(e.currentTarget);
- const definitionIndex = Display.entryIndexFind(link);
- const expressionIndex = link.closest('.entry').find('.expression .action-play-audio').index(link);
+ const link = e.currentTarget;
+ const entry = link.closest('.entry');
+ const definitionIndex = this.entryIndexFind(entry);
+ const expressionIndex = Display.indexOf(entry.querySelectorAll('.expression .action-play-audio'), link);
this.audioPlay(this.definitions[definitionIndex], expressionIndex);
}
onNoteAdd(e) {
e.preventDefault();
- const link = $(e.currentTarget);
- const index = Display.entryIndexFind(link);
- this.noteAdd(this.definitions[index], link.data('mode'));
+ const link = e.currentTarget;
+ const index = this.entryIndexFind(link);
+ this.noteAdd(this.definitions[index], link.dataset.mode);
}
onNoteView(e) {
e.preventDefault();
- const link = $(e.currentTarget);
- const index = Display.entryIndexFind(link);
- apiNoteView(link.data('noteId'));
+ const link = e.currentTarget;
+ apiNoteView(link.dataset.noteId);
}
onKeyDown(e) {
@@ -556,8 +556,9 @@ class Display {
return result;
}
- static entryIndexFind(element) {
- return $('.entry').index(element.closest('.entry'));
+ entryIndexFind(element) {
+ const entry = element.closest('.entry');
+ return entry !== null ? Display.indexOf(this.container.get(0).querySelectorAll('.entry'), entry) : -1;
}
static adderButtonFind(index, mode) {
@@ -571,4 +572,13 @@ class Display {
static delay(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
+
+ static indexOf(nodeList, node) {
+ for (let i = 0, ii = nodeList.length; i < ii; ++i) {
+ if (nodeList[i] === node) {
+ return i;
+ }
+ }
+ return -1;
+ }
}