Require context for setContentTerms and setContentKanji

This commit is contained in:
toasted-nutbread 2019-11-26 11:43:58 -05:00
parent cfa16ce675
commit c7cb1b3d9e

View File

@ -326,6 +326,7 @@ class Display {
} }
async setContentTerms(definitions, context) { async setContentTerms(definitions, context) {
if (!context) { throw new Error('Context expected'); }
if (!this.isInitialized()) { return; } if (!this.isInitialized()) { return; }
try { try {
@ -333,7 +334,7 @@ class Display {
this.setEventListenersActive(false); this.setEventListenersActive(false);
if (!context || context.focus !== false) { if (context.focus !== false) {
window.focus(); window.focus();
} }
@ -343,7 +344,7 @@ class Display {
const sequence = ++this.sequence; const sequence = ++this.sequence;
const params = { const params = {
definitions, definitions,
source: context && context.source, source: context.source,
addable: options.anki.enable, addable: options.anki.enable,
grouped: options.general.resultOutputMode === 'group', grouped: options.general.resultOutputMode === 'group',
merged: options.general.resultOutputMode === 'merge', merged: options.general.resultOutputMode === 'merge',
@ -352,19 +353,14 @@ class Display {
debug: options.general.debugInfo debug: options.general.debugInfo
}; };
if (context) { for (const definition of definitions) {
for (const definition of definitions) { definition.cloze = Display.clozeBuild(context.sentence, definition.source);
if (context.sentence) { definition.url = context.url;
definition.cloze = Display.clozeBuild(context.sentence, definition.source);
}
definition.url = context.url;
}
} }
const content = await apiTemplateRender('terms.html', params); const content = await apiTemplateRender('terms.html', params);
this.container.innerHTML = content; this.container.innerHTML = content;
const {index, scroll, disableScroll} = context || {}; const {index, scroll, disableScroll} = context;
if (!disableScroll) { if (!disableScroll) {
this.entryScrollIntoView(index || 0, scroll); this.entryScrollIntoView(index || 0, scroll);
} }
@ -382,6 +378,7 @@ class Display {
} }
async setContentKanji(definitions, context) { async setContentKanji(definitions, context) {
if (!context) { throw new Error('Context expected'); }
if (!this.isInitialized()) { return; } if (!this.isInitialized()) { return; }
try { try {
@ -389,7 +386,7 @@ class Display {
this.setEventListenersActive(false); this.setEventListenersActive(false);
if (!context || context.focus !== false) { if (context.focus !== false) {
window.focus(); window.focus();
} }
@ -399,24 +396,19 @@ class Display {
const sequence = ++this.sequence; const sequence = ++this.sequence;
const params = { const params = {
definitions, definitions,
source: context && context.source, source: context.source,
addable: options.anki.enable, addable: options.anki.enable,
debug: options.general.debugInfo debug: options.general.debugInfo
}; };
if (context) { for (const definition of definitions) {
for (const definition of definitions) { definition.cloze = Display.clozeBuild(context.sentence);
if (context.sentence) { definition.url = context.url;
definition.cloze = Display.clozeBuild(context.sentence);
}
definition.url = context.url;
}
} }
const content = await apiTemplateRender('kanji.html', params); const content = await apiTemplateRender('kanji.html', params);
this.container.innerHTML = content; this.container.innerHTML = content;
const {index, scroll} = context || {}; const {index, scroll} = context;
this.entryScrollIntoView(index || 0, scroll); this.entryScrollIntoView(index || 0, scroll);
this.setEventListenersActive(true); this.setEventListenersActive(true);