summaryrefslogtreecommitdiff
path: root/ext/mixed/js/display.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-10-30 03:58:24 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 17:40:52 +0200
commitc35a05cd62d43ff435c022a353de55510b020277 (patch)
treeeed5ca7f70aed856ec2be69b39013202dfcba596 /ext/mixed/js/display.js
parentf63e8e4be0e7bdb1a2e45e349bf667ea7ca4adab (diff)
add kana to text
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r--ext/mixed/js/display.js78
1 files changed, 53 insertions, 25 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 07a851f5..82385bf9 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -98,17 +98,62 @@ class Display {
}
}
- async onTermLookup(e) {
+ async onTermLookup(e, {disableScroll, selectText, disableHistory}) {
+ const termLookupResults = await this.termLookup(e);
+ if (!termLookupResults) {
+ return false;
+ }
+
+ try {
+ const {textSource, definitions} = termLookupResults;
+
+ const scannedElement = e.target;
+ const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
+
+ if (!disableScroll) {
+ this.windowScroll.toY(0);
+ }
+ let context;
+ if (disableHistory) {
+ const {url, source} = this.context || {};
+ context = {sentence, url, source, disableScroll};
+ } else {
+ context = {
+ disableScroll,
+ source: {
+ definitions: this.definitions,
+ index: this.entryIndexFind(scannedElement),
+ scroll: this.windowScroll.y
+ }
+ };
+
+ if (this.context) {
+ context.sentence = sentence;
+ context.url = this.context.url;
+ context.source.source = this.context.source;
+ }
+ }
+
+ this.setContentTerms(definitions, context);
+
+ if (selectText) {
+ textSource.select();
+ }
+ } catch (error) {
+ this.onError(error);
+ }
+ }
+
+ async termLookup(e) {
try {
e.preventDefault();
- const clickedElement = e.target;
const textSource = docRangeFromPoint(e.clientX, e.clientY, this.options);
if (textSource === null) {
return false;
}
- let definitions, length, sentence;
+ let definitions, length;
try {
textSource.setEndOffset(this.options.scanning.length);
@@ -118,30 +163,11 @@ class Display {
}
textSource.setEndOffset(length);
-
- sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
} finally {
textSource.cleanup();
}
- this.windowScroll.toY(0);
- const context = {
- source: {
- definitions: this.definitions,
- index: this.entryIndexFind(clickedElement),
- scroll: this.windowScroll.y
- }
- };
-
- if (this.context) {
- context.sentence = sentence;
- context.url = this.context.url;
- context.source.source = this.context.source;
- }
-
- this.setContentTerms(definitions, context);
-
- return {textSource};
+ return {textSource, definitions};
} catch (error) {
this.onError(error);
}
@@ -338,8 +364,10 @@ class Display {
const content = await apiTemplateRender('terms.html', params);
this.container.innerHTML = content;
- const {index, scroll} = context || {};
- this.entryScrollIntoView(index || 0, scroll);
+ const {index, scroll, disableScroll} = context || {};
+ if (!disableScroll) {
+ this.entryScrollIntoView(index || 0, scroll);
+ }
if (options.audio.enabled && options.audio.autoPlay) {
this.autoPlayAudio();