Update how source terms are navigated
This commit is contained in:
parent
c7cb1b3d9e
commit
cb9f9b585a
@ -58,23 +58,25 @@ class Display {
|
|||||||
async onKanjiLookup(e) {
|
async onKanjiLookup(e) {
|
||||||
try {
|
try {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if (!this.context) { return; }
|
||||||
|
|
||||||
const link = e.target;
|
const link = e.target;
|
||||||
this.windowScroll.toY(0);
|
this.windowScroll.toY(0);
|
||||||
const context = {
|
const context = {
|
||||||
source: {
|
source: {
|
||||||
|
type: 'terms',
|
||||||
|
details: {
|
||||||
definitions: this.definitions,
|
definitions: this.definitions,
|
||||||
|
context: Object.assign({}, this.context, {
|
||||||
index: this.entryIndexFind(link),
|
index: this.entryIndexFind(link),
|
||||||
scroll: this.windowScroll.y
|
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());
|
const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext());
|
||||||
this.setContentKanji(definitions, context);
|
this.setContentKanji(definitions, context);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -99,12 +101,10 @@ class Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) {
|
async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) {
|
||||||
const termLookupResults = await this.termLookup(e);
|
|
||||||
if (!termLookupResults) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!this.context) { return; }
|
||||||
|
const termLookupResults = await this.termLookup(e);
|
||||||
|
if (!termLookupResults) { return; }
|
||||||
const {textSource, definitions} = termLookupResults;
|
const {textSource, definitions} = termLookupResults;
|
||||||
|
|
||||||
const scannedElement = e.target;
|
const scannedElement = e.target;
|
||||||
@ -113,27 +113,23 @@ class Display {
|
|||||||
if (!disableScroll) {
|
if (!disableScroll) {
|
||||||
this.windowScroll.toY(0);
|
this.windowScroll.toY(0);
|
||||||
}
|
}
|
||||||
let context;
|
|
||||||
if (disableHistory) {
|
const context = {
|
||||||
const {url, source} = this.context || {};
|
source: disableHistory ? this.context.source : {
|
||||||
context = {sentence, url, source, disableScroll};
|
type: 'terms',
|
||||||
} else {
|
details: {
|
||||||
context = {
|
|
||||||
disableScroll,
|
|
||||||
source: {
|
|
||||||
definitions: this.definitions,
|
definitions: this.definitions,
|
||||||
|
context: Object.assign({}, this.context, {
|
||||||
index: this.entryIndexFind(scannedElement),
|
index: this.entryIndexFind(scannedElement),
|
||||||
scroll: this.windowScroll.y
|
scroll: this.windowScroll.y
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
disableScroll,
|
||||||
|
sentence,
|
||||||
|
url: this.context.url
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.context) {
|
|
||||||
context.sentence = sentence;
|
|
||||||
context.url = this.context.url;
|
|
||||||
context.source.source = this.context.source;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setContentTerms(definitions, context);
|
this.setContentTerms(definitions, context);
|
||||||
|
|
||||||
if (selectText) {
|
if (selectText) {
|
||||||
@ -501,17 +497,9 @@ class Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceTermView() {
|
sourceTermView() {
|
||||||
if (this.context && this.context.source) {
|
if (!this.context || !this.context.source) { return; }
|
||||||
const context = {
|
const {type, details} = this.context.source;
|
||||||
url: this.context.source.url,
|
this.setContent(type, details);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
noteTryAdd(mode) {
|
noteTryAdd(mode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user