summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/query-parser-generator.js (renamed from ext/bg/js/search-query-parser-generator.js)0
-rw-r--r--ext/bg/js/query-parser.js (renamed from ext/bg/js/search-query-parser.js)21
-rw-r--r--ext/bg/js/search.js16
-rw-r--r--ext/bg/search.html4
4 files changed, 29 insertions, 12 deletions
diff --git a/ext/bg/js/search-query-parser-generator.js b/ext/bg/js/query-parser-generator.js
index 6989e157..6989e157 100644
--- a/ext/bg/js/search-query-parser-generator.js
+++ b/ext/bg/js/query-parser-generator.js
diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/query-parser.js
index 86524b66..88c40c93 100644
--- a/ext/bg/js/search-query-parser.js
+++ b/ext/bg/js/query-parser.js
@@ -22,11 +22,11 @@
* docSentenceExtract
*/
-class QueryParser {
- constructor({getOptionsContext, setContent, setSpinnerVisible}) {
+class QueryParser extends EventDispatcher {
+ constructor({getOptionsContext, setSpinnerVisible}) {
+ super();
this._options = null;
this._getOptionsContext = getOptionsContext;
- this._setContent = setContent;
this._setSpinnerVisible = setSpinnerVisible;
this._parseResults = [];
this._queryParser = document.querySelector('#query-parser-content');
@@ -80,7 +80,8 @@ class QueryParser {
const searchText = this._textScanner.getTextSourceContent(textSource, scanLength, layoutAwareScan);
if (searchText.length === 0) { return null; }
- const {definitions, length} = await api.termsFind(searchText, {}, this._getOptionsContext());
+ const optionsContext = this._getOptionsContext();
+ const {definitions, length} = await api.termsFind(searchText, {}, optionsContext);
if (definitions.length === 0) { return null; }
const sentenceExtent = this._options.anki.sentenceExt;
@@ -88,12 +89,14 @@ class QueryParser {
textSource.setEndOffset(length, layoutAwareScan);
- this._setContent('terms', {definitions, context: {
- focus: false,
- disableHistory: cause === 'mouse',
+ this.trigger('searched', {
+ type: 'terms',
+ definitions,
sentence,
- url: window.location.href
- }});
+ cause,
+ textSource,
+ optionsContext
+ });
return {definitions, type: 'terms'};
}
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 5be71555..b3e3ebca 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -40,7 +40,6 @@ class DisplaySearch extends Display {
});
this._queryParser = new QueryParser({
getOptionsContext: this.getOptionsContext.bind(this),
- setContent: this.setContent.bind(this),
setSpinnerVisible: this.setSpinnerVisible.bind(this)
});
this._onKeyDownIgnoreKeys = new Map([
@@ -67,6 +66,9 @@ class DisplaySearch extends Display {
await this.updateOptions();
yomichan.on('optionsUpdated', () => this.updateOptions());
await this._queryParser.prepare();
+
+ this._queryParser.on('searched', this._onQueryParserSearch.bind(this));
+
const options = this.getOptions();
const {queryParams: {query='', mode=''}} = parseUrl(window.location.href);
@@ -169,6 +171,18 @@ class DisplaySearch extends Display {
// Private
+ _onQueryParserSearch({type, definitions, sentence, cause}) {
+ this.setContent(type, {
+ definitions,
+ context: {
+ focus: false,
+ disableHistory: cause === 'mouse',
+ sentence,
+ url: window.location.href
+ }
+ });
+ }
+
_onSearchInput() {
this._updateSearchButton();
diff --git a/ext/bg/search.html b/ext/bg/search.html
index cfcf1f96..8f7c1d4c 100644
--- a/ext/bg/search.html
+++ b/ext/bg/search.html
@@ -92,8 +92,8 @@
<script src="/mixed/js/text-scanner.js"></script>
<script src="/mixed/js/template-handler.js"></script>
- <script src="/bg/js/search-query-parser-generator.js"></script>
- <script src="/bg/js/search-query-parser.js"></script>
+ <script src="/bg/js/query-parser-generator.js"></script>
+ <script src="/bg/js/query-parser.js"></script>
<script src="/bg/js/clipboard-monitor.js"></script>
<script src="/bg/js/search.js"></script>