summaryrefslogtreecommitdiff
path: root/ext/bg/js/yomichan.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-04 11:45:55 -0800
committerAlex Yatskov <alex@foosoft.net>2017-03-04 11:45:55 -0800
commitb1950cf47eea6e1e4713285fc883ad6c9ac043c6 (patch)
tree0b4eec95b4519770dfb91ad70f9faaf577b763ab /ext/bg/js/yomichan.js
parentca6d12dd626ba8da9103525462d59f3d63927a93 (diff)
prelim search support
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r--ext/bg/js/yomichan.js45
1 files changed, 23 insertions, 22 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 63e3e959..898f2eea 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -126,39 +126,40 @@ class Yomichan {
return note;
}
+ termsFind(text) {
+ const searcher = this.options.general.groupResults ?
+ this.translator.findTermsGrouped.bind(this.translator) :
+ this.translator.findTerms.bind(this.translator);
+
+ return searcher(text, dictEnabled(this.options), this.options.general.softKatakana).then(({definitions, length}) => {
+ return {length, definitions: definitions.slice(0, this.options.general.maxResults)};
+ });
+ }
+
+ kanjiFind(text) {
+ return this.translator.findKanji(text, dictEnabled(this.options)).then(definitions => {
+ return definitions.slice(0, this.options.general.maxResults);
+ });
+ }
+
+ textRender(template, data) {
+ return Handlebars.templates[template](data);
+ }
+
api_optionsGet({callback}) {
promiseCallback(optionsLoad(), callback);
}
api_kanjiFind({text, callback}) {
- promiseCallback(
- this.translator.findKanji(text, dictEnabled(this.options)).then(definitions => {
- return definitions.slice(0, this.options.general.maxResults);
- }),
- callback
- );
+ promiseCallback(this.kanjiFind(text), callback);
}
api_termsFind({text, callback}) {
- promiseCallback(
- this.translator.findTerms(text, dictEnabled(this.options), this.options.general.softKatakana).then(({definitions, length}) => {
- return {length, definitions: definitions.slice(0, this.options.general.maxResults)};
- }),
- callback
- );
- }
-
- api_termsFindGrouped({text, callback}) {
- promiseCallback(
- this.translator.findTermsGrouped(text, dictEnabled(this.options), this.options.general.softKatakana).then(({definitions, length}) => {
- return {length, definitions: definitions.slice(0, this.options.general.maxResults)};
- }),
- callback
- );
+ promiseCallback(this.termsFind(text), callback);
}
api_textRender({template, data, callback}) {
- callback({result: Handlebars.templates[template](data)});
+ callback({result: this.textRender(template, data)});
}
api_definitionAdd({definition, mode, callback}) {