summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/search.js46
1 files changed, 32 insertions, 14 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index ead9ba6f..7a8fdf5e 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -33,23 +33,37 @@ class DisplaySearch extends Display {
this.introAnimationTimer = null;
this.dependencies = Object.assign({}, this.dependencies, {docRangeFromPoint, docSentenceExtract});
+ }
- if (this.search !== null) {
- this.search.addEventListener('click', (e) => this.onSearch(e), false);
- }
- if (this.query !== null) {
- this.query.addEventListener('input', () => this.onSearchInput(), false);
+ static create() {
+ const instance = new DisplaySearch();
+ instance.prepare();
+ return instance;
+ }
+
+ async prepare() {
+ try {
+ await this.initialize();
- const query = DisplaySearch.getSearchQueryFromLocation(window.location.href);
- if (query !== null) {
- this.query.value = window.wanakana.toKana(query);
- this.onSearchQueryUpdated(query, false);
+ if (this.search !== null) {
+ this.search.addEventListener('click', (e) => this.onSearch(e), false);
}
+ if (this.query !== null) {
+ this.query.addEventListener('input', () => this.onSearchInput(), false);
- window.wanakana.bind(this.query);
- }
+ const query = DisplaySearch.getSearchQueryFromLocation(window.location.href);
+ if (query !== null) {
+ this.query.value = window.wanakana.toKana(query);
+ this.onSearchQueryUpdated(query, false);
+ }
- this.updateSearchButton();
+ window.wanakana.bind(this.query);
+ }
+
+ this.updateSearchButton();
+ } catch (e) {
+ this.onError(e);
+ }
}
onError(error) {
@@ -89,7 +103,7 @@ class DisplaySearch extends Display {
this.updateSearchButton();
if (valid) {
const {definitions} = await apiTermsFind(query, this.optionsContext);
- this.termsShow(definitions, await apiOptionsGet(this.optionsContext));
+ this.termsShow(definitions, this.options);
} else {
this.container.textContent = '';
}
@@ -98,6 +112,10 @@ class DisplaySearch extends Display {
}
}
+ getOptionsContext() {
+ return this.optionsContext;
+ }
+
setIntroVisible(visible, animate) {
if (this.introVisible === visible) {
return;
@@ -164,4 +182,4 @@ class DisplaySearch extends Display {
}
}
-window.yomichan_search = new DisplaySearch();
+window.yomichan_search = DisplaySearch.create();