Use raw element references for container and spinner

This commit is contained in:
toasted-nutbread 2019-09-15 14:16:23 -04:00
parent 355fb29c3b
commit 95a7fd81f5
3 changed files with 13 additions and 9 deletions

View File

@ -19,7 +19,7 @@
class DisplaySearch extends Display { class DisplaySearch extends Display {
constructor() { constructor() {
super($('#spinner'), $('#content')); super(document.querySelector('#spinner'), document.querySelector('#content'));
this.optionsContext = { this.optionsContext = {
depth: 0, depth: 0,

View File

@ -19,7 +19,7 @@
class DisplayFloat extends Display { class DisplayFloat extends Display {
constructor() { constructor() {
super($('#spinner'), $('#definitions')); super(document.querySelector('#spinner'), document.querySelector('#definitions'));
this.autoPlayAudioTimer = null; this.autoPlayAudioTimer = null;
this.styleNode = null; this.styleNode = null;

View File

@ -310,7 +310,7 @@ class Display {
} }
const content = await apiTemplateRender('terms.html', params); const content = await apiTemplateRender('terms.html', params);
this.container.html(content); this.container.innerHTML = content;
const {index, scroll} = context || {}; const {index, scroll} = context || {};
this.entryScrollIntoView(index || 0, scroll); this.entryScrollIntoView(index || 0, scroll);
@ -362,7 +362,7 @@ class Display {
} }
const content = await apiTemplateRender('kanji.html', params); const content = await apiTemplateRender('kanji.html', params);
this.container.html(content); this.container.innerHTML = content;
const {index, scroll} = context || {}; const {index, scroll} = context || {};
this.entryScrollIntoView(index || 0, scroll); this.entryScrollIntoView(index || 0, scroll);
@ -446,7 +446,7 @@ class Display {
async noteAdd(definition, mode) { async noteAdd(definition, mode) {
try { try {
this.spinner.show(); this.setSpinnerVisible(true);
const context = {}; const context = {};
if (this.noteUsesScreenshot()) { if (this.noteUsesScreenshot()) {
@ -467,13 +467,13 @@ class Display {
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} finally { } finally {
this.spinner.hide(); this.setSpinnerVisible(false);
} }
} }
async audioPlay(definition, expressionIndex) { async audioPlay(definition, expressionIndex) {
try { try {
this.spinner.show(); this.setSpinnerVisible(true);
const expression = expressionIndex === -1 ? definition : definition.expressions[expressionIndex]; const expression = expressionIndex === -1 ? definition : definition.expressions[expressionIndex];
let url = await apiAudioGetUrl(expression, this.options.general.audioSource); let url = await apiAudioGetUrl(expression, this.options.general.audioSource);
@ -505,7 +505,7 @@ class Display {
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} finally { } finally {
this.spinner.hide(); this.setSpinnerVisible(false);
} }
} }
@ -542,6 +542,10 @@ class Display {
return apiForward('popupSetVisible', {visible}); return apiForward('popupSetVisible', {visible});
} }
setSpinnerVisible(visible) {
this.spinner.style.display = visible ? 'block' : '';
}
static clozeBuild(sentence, source) { static clozeBuild(sentence, source) {
const result = { const result = {
sentence: sentence.text.trim() sentence: sentence.text.trim()
@ -558,7 +562,7 @@ class Display {
entryIndexFind(element) { entryIndexFind(element) {
const entry = element.closest('.entry'); const entry = element.closest('.entry');
return entry !== null ? Display.indexOf(this.container.get(0).querySelectorAll('.entry'), entry) : -1; return entry !== null ? Display.indexOf(this.container.querySelectorAll('.entry'), entry) : -1;
} }
static adderButtonFind(index, mode) { static adderButtonFind(index, mode) {