summaryrefslogtreecommitdiff
path: root/ext/bg/js/search.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-03-21 22:29:07 +0200
committerGitHub <noreply@github.com>2020-03-21 22:29:07 +0200
commit08d38d8db2c97ff9f016a6de640f645b609088d1 (patch)
tree9060deb6f870e472c601b6cec050a2f60f62abca /ext/bg/js/search.js
parent647769f2baae338f201690f21c4bf8983bcb10b0 (diff)
parentb616bac66ed0735c1e7ebbaf1ceba20b081f1a6f (diff)
Merge pull request #411 from siikamiika/apply-all-options-profile-change
apply all options on profile change
Diffstat (limited to 'ext/bg/js/search.js')
-rw-r--r--ext/bg/js/search.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index e2bdff73..9250fdde 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -29,12 +29,18 @@ class DisplaySearch extends Display {
constructor() {
super(document.querySelector('#spinner'), document.querySelector('#content'));
+ this._isPrepared = false;
+
this.optionsContext = {
depth: 0,
url: window.location.href
};
- this.queryParser = new QueryParser(this);
+ this.queryParser = new QueryParser({
+ getOptionsContext: this.getOptionsContext.bind(this),
+ setContent: this.setContent.bind(this),
+ setSpinnerVisible: this.setSpinnerVisible.bind(this)
+ });
this.search = document.querySelector('#search');
this.query = document.querySelector('#query');
@@ -112,6 +118,8 @@ class DisplaySearch extends Display {
this.clipboardMonitor.on('change', this.onExternalSearchUpdate.bind(this));
this.updateSearchButton();
+
+ this._isPrepared = true;
} catch (e) {
this.onError(e);
}
@@ -247,15 +255,12 @@ class DisplaySearch extends Display {
}
onWanakanaEnableChange(e) {
- const {queryParams: {query=''}} = parseUrl(window.location.href);
const enableWanakana = e.target.checked;
if (enableWanakana) {
window.wanakana.bind(this.query);
} else {
window.wanakana.unbind(this.query);
}
- this.setQuery(query);
- this.onSearchQueryUpdated(this.query.value, false);
apiOptionsSet({general: {enableWanakana}}, this.getOptionsContext());
}
@@ -278,19 +283,21 @@ class DisplaySearch extends Display {
}
}
- async updateOptions(options) {
- await super.updateOptions(options);
+ async updateOptions() {
+ await super.updateOptions();
this.queryParser.setOptions(this.options);
+ if (!this._isPrepared) { return; }
+ const query = this.query.value;
+ if (query) {
+ this.setQuery(query);
+ this.onSearchQueryUpdated(query, false);
+ }
}
isWanakanaEnabled() {
return this.wanakanaEnable !== null && this.wanakanaEnable.checked;
}
- getOptionsContext() {
- return this.optionsContext;
- }
-
setQuery(query) {
const interpretedQuery = this.isWanakanaEnabled() ? window.wanakana.toKana(query) : query;
this.query.value = interpretedQuery;