diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-11-26 12:29:49 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-11-26 12:31:20 -0500 |
commit | cb9f9b585a802c7b8dfb5689d326e7482f5ff2db (patch) | |
tree | b5dbf7f1a66a1b3ed818f0b0611770a9007bae99 /ext/mixed/js/display.js | |
parent | c7cb1b3d9e5d738e36175b850a9c696a3ab0bf6d (diff) |
Update how source terms are navigated
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r-- | ext/mixed/js/display.js | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 651a43c9..cbf8efb7 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -58,23 +58,25 @@ class Display { async onKanjiLookup(e) { try { e.preventDefault(); + if (!this.context) { return; } const link = e.target; this.windowScroll.toY(0); const context = { source: { - definitions: this.definitions, - index: this.entryIndexFind(link), - scroll: this.windowScroll.y - } + type: 'terms', + details: { + definitions: this.definitions, + context: Object.assign({}, this.context, { + index: this.entryIndexFind(link), + scroll: this.windowScroll.y + }) + } + }, + sentence: this.context.sentence, + url: this.context.url }; - if (this.context) { - context.sentence = this.context.sentence; - context.url = this.context.url; - context.source.source = this.context.source; - } - const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); this.setContentKanji(definitions, context); } catch (error) { @@ -99,12 +101,10 @@ class Display { } async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { - const termLookupResults = await this.termLookup(e); - if (!termLookupResults) { - return false; - } - try { + if (!this.context) { return; } + const termLookupResults = await this.termLookup(e); + if (!termLookupResults) { return; } const {textSource, definitions} = termLookupResults; const scannedElement = e.target; @@ -113,26 +113,22 @@ class Display { if (!disableScroll) { this.windowScroll.toY(0); } - let context; - if (disableHistory) { - const {url, source} = this.context || {}; - context = {sentence, url, source, disableScroll}; - } else { - context = { - disableScroll, - source: { + + const context = { + source: disableHistory ? this.context.source : { + type: 'terms', + details: { definitions: this.definitions, - index: this.entryIndexFind(scannedElement), - scroll: this.windowScroll.y + context: Object.assign({}, this.context, { + 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; - } - } + }, + disableScroll, + sentence, + url: this.context.url + }; this.setContentTerms(definitions, context); @@ -501,17 +497,9 @@ class Display { } sourceTermView() { - if (this.context && this.context.source) { - const context = { - url: this.context.source.url, - sentence: this.context.source.sentence, - index: this.context.source.index, - scroll: this.context.source.scroll, - source: this.context.source.source - }; - - this.setContentTerms(this.context.source.definitions, context); - } + if (!this.context || !this.context.source) { return; } + const {type, details} = this.context.source; + this.setContent(type, details); } noteTryAdd(mode) { |