From e36bc8771fd0b79a43cd809041002879f862487d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 3 Jul 2020 12:02:21 -0400 Subject: Display refactor (#643) * Remove statics * Move orphan detection and error handling to Display * Add clearContent function * Add/use public get/set functions for optionsContext * Add public getOptions * Move interactive assignment * Mark fields as private * Mark functions as private * Change stray getter into a function --- ext/bg/js/search.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'ext/bg/js/search.js') diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index e968e8cf..e9ec2b85 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -33,10 +33,10 @@ class DisplaySearch extends Display { this._isPrepared = false; - this.optionsContext = { + this.setOptionsContext({ depth: 0, url: window.location.href - }; + }); this.queryParser = new QueryParser({ getOptionsContext: this.getOptionsContext.bind(this), @@ -80,12 +80,13 @@ class DisplaySearch extends Display { await this.updateOptions(); yomichan.on('optionsUpdated', () => this.updateOptions()); await this.queryParser.prepare(); + const options = this.getOptions(); const {queryParams: {query='', mode=''}} = parseUrl(window.location.href); document.documentElement.dataset.searchMode = mode; - if (this.options.general.enableWanakana === true) { + if (options.general.enableWanakana === true) { this.wanakanaEnable.checked = true; wanakana.bind(this.query); } else { @@ -96,7 +97,7 @@ class DisplaySearch extends Display { this.onSearchQueryUpdated(this.query.value, false); if (mode !== 'popup') { - if (this.options.general.enableClipboardMonitor === true) { + if (options.general.enableClipboardMonitor === true) { this.clipboardMonitorEnable.checked = true; this.clipboardMonitor.start(); } else { @@ -121,10 +122,6 @@ class DisplaySearch extends Display { this._isPrepared = true; } - onError(error) { - yomichan.logError(error); - } - onEscape() { if (this.query === null) { return; @@ -241,7 +238,7 @@ class DisplaySearch extends Display { url: window.location.href }}); } else { - this.container.textContent = ''; + this.clearContent(); } this.setTitleText(query); window.parent.postMessage('popupClose', '*'); @@ -299,7 +296,8 @@ class DisplaySearch extends Display { async updateOptions() { await super.updateOptions(); - this.queryParser.setOptions(this.options); + const options = this.getOptions(); + this.queryParser.setOptions(options); if (!this._isPrepared) { return; } const query = this.query.value; if (query) { -- cgit v1.2.3