summaryrefslogtreecommitdiff
path: root/ext/bg/js/search.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-11-26 18:31:35 +0200
committerGitHub <noreply@github.com>2019-11-26 18:31:35 +0200
commit3423ed7d67ff7039d21da0b734e306b2c1024643 (patch)
tree92193ecc5e041a47f2afa8417adf17e215381e1e /ext/bg/js/search.js
parent820beb7c9338bd81501d1779b10181c7cced9992 (diff)
parent89c6ef54b0a44685cde530dd4a94405a578ce132 (diff)
Merge pull request #279 from siikamiika/query-parser-1
Search page query parser
Diffstat (limited to 'ext/bg/js/search.js')
-rw-r--r--ext/bg/js/search.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index ec5a5972..b4731e6a 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -32,6 +32,8 @@ class DisplaySearch extends Display {
url: window.location.href
};
+ this.queryParser = new QueryParser(this);
+
this.search = document.querySelector('#search');
this.query = document.querySelector('#query');
this.intro = document.querySelector('#intro');
@@ -72,11 +74,11 @@ class DisplaySearch extends Display {
const query = DisplaySearch.getSearchQueryFromLocation(window.location.href) || '';
if (e.target.checked) {
window.wanakana.bind(this.query);
- this.query.value = window.wanakana.toKana(query);
+ this.setQuery(window.wanakana.toKana(query));
apiOptionsSet({general: {enableWanakana: true}}, this.getOptionsContext());
} else {
window.wanakana.unbind(this.query);
- this.query.value = query;
+ this.setQuery(query);
apiOptionsSet({general: {enableWanakana: false}}, this.getOptionsContext());
}
this.onSearchQueryUpdated(this.query.value, false);
@@ -86,9 +88,9 @@ class DisplaySearch extends Display {
const query = DisplaySearch.getSearchQueryFromLocation(window.location.href);
if (query !== null) {
if (this.isWanakanaEnabled()) {
- this.query.value = window.wanakana.toKana(query);
+ this.setQuery(window.wanakana.toKana(query));
} else {
- this.query.value = query;
+ this.setQuery(query);
}
this.onSearchQueryUpdated(this.query.value, false);
}
@@ -159,6 +161,7 @@ class DisplaySearch extends Display {
e.preventDefault();
const query = this.query.value;
+ this.queryParser.setText(query);
const queryString = query.length > 0 ? `?query=${encodeURIComponent(query)}` : '';
window.history.pushState(null, '', `${window.location.pathname}${queryString}`);
this.onSearchQueryUpdated(query, true);
@@ -168,9 +171,9 @@ class DisplaySearch extends Display {
const query = DisplaySearch.getSearchQueryFromLocation(window.location.href) || '';
if (this.query !== null) {
if (this.isWanakanaEnabled()) {
- this.query.value = window.wanakana.toKana(query);
+ this.setQuery(window.wanakana.toKana(query));
} else {
- this.query.value = query;
+ this.setQuery(query);
}
}
@@ -258,9 +261,9 @@ class DisplaySearch extends Display {
}
if (curText && (curText !== this.clipboardPrevText) && jpIsJapaneseText(curText)) {
if (this.isWanakanaEnabled()) {
- this.query.value = window.wanakana.toKana(curText);
+ this.setQuery(window.wanakana.toKana(curText));
} else {
- this.query.value = curText;
+ this.setQuery(curText);
}
const queryString = curText.length > 0 ? `?query=${encodeURIComponent(curText)}` : '';
@@ -287,6 +290,11 @@ class DisplaySearch extends Display {
return this.optionsContext;
}
+ setQuery(query) {
+ this.query.value = query;
+ this.queryParser.setText(query);
+ }
+
setIntroVisible(visible, animate) {
if (this.introVisible === visible) {
return;