From c7cb1b3d9e5d738e36175b850a9c696a3ab0bf6d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 11:43:58 -0500 Subject: [PATCH] Require context for setContentTerms and setContentKanji --- ext/mixed/js/display.js | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 4c698ecf..651a43c9 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -326,6 +326,7 @@ class Display { } async setContentTerms(definitions, context) { + if (!context) { throw new Error('Context expected'); } if (!this.isInitialized()) { return; } try { @@ -333,7 +334,7 @@ class Display { this.setEventListenersActive(false); - if (!context || context.focus !== false) { + if (context.focus !== false) { window.focus(); } @@ -343,7 +344,7 @@ class Display { const sequence = ++this.sequence; const params = { definitions, - source: context && context.source, + source: context.source, addable: options.anki.enable, grouped: options.general.resultOutputMode === 'group', merged: options.general.resultOutputMode === 'merge', @@ -352,19 +353,14 @@ class Display { debug: options.general.debugInfo }; - if (context) { - for (const definition of definitions) { - if (context.sentence) { - definition.cloze = Display.clozeBuild(context.sentence, definition.source); - } - - definition.url = context.url; - } + for (const definition of definitions) { + definition.cloze = Display.clozeBuild(context.sentence, definition.source); + definition.url = context.url; } const content = await apiTemplateRender('terms.html', params); this.container.innerHTML = content; - const {index, scroll, disableScroll} = context || {}; + const {index, scroll, disableScroll} = context; if (!disableScroll) { this.entryScrollIntoView(index || 0, scroll); } @@ -382,6 +378,7 @@ class Display { } async setContentKanji(definitions, context) { + if (!context) { throw new Error('Context expected'); } if (!this.isInitialized()) { return; } try { @@ -389,7 +386,7 @@ class Display { this.setEventListenersActive(false); - if (!context || context.focus !== false) { + if (context.focus !== false) { window.focus(); } @@ -399,24 +396,19 @@ class Display { const sequence = ++this.sequence; const params = { definitions, - source: context && context.source, + source: context.source, addable: options.anki.enable, debug: options.general.debugInfo }; - if (context) { - for (const definition of definitions) { - if (context.sentence) { - definition.cloze = Display.clozeBuild(context.sentence); - } - - definition.url = context.url; - } + for (const definition of definitions) { + definition.cloze = Display.clozeBuild(context.sentence); + definition.url = context.url; } const content = await apiTemplateRender('kanji.html', params); this.container.innerHTML = content; - const {index, scroll} = context || {}; + const {index, scroll} = context; this.entryScrollIntoView(index || 0, scroll); this.setEventListenersActive(true);