summaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-01-08 15:33:45 -0800
committerAlex Yatskov <alex@foosoft.net>2017-01-08 15:33:45 -0800
commit148291d3a7cea096317c1c8d22f06f6e18cfdcfb (patch)
tree7ac7bb03cc980d3c1bd6cbdb84f6a8b6851012b9 /ext/fg
parent0498ea5d361867f34b6b813178a39709e8bea68e (diff)
WIP
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/js/driver.js11
-rw-r--r--ext/fg/js/frame.js31
-rw-r--r--ext/fg/js/popup.js4
-rw-r--r--ext/fg/js/util.js4
4 files changed, 48 insertions, 2 deletions
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js
index c0e328d5..12003d55 100644
--- a/ext/fg/js/driver.js
+++ b/ext/fg/js/driver.js
@@ -146,7 +146,14 @@ class Driver {
searchTerms(textSource) {
textSource.setEndOffset(this.options.scanLength);
- return findTerm(textSource.text()).then(({definitions, length}) => {
+ let findFunc = findTerm;
+ let showFunc = this.popup.showTermDefs.bind(this.popup);
+ if (this.options.groupTermResults) {
+ findFunc = findTermGrouped;
+ showFunc = this.popup.showTermGroupedDefs.bind(this.popup);
+ }
+
+ return findFunc(textSource.text()).then(({definitions, length}) => {
if (definitions.length === 0) {
return false;
} else {
@@ -159,7 +166,7 @@ class Driver {
});
this.popup.showNextTo(textSource.getRect());
- this.popup.showTermDefs(definitions, this.options);
+ showFunc(definitions, this.options);
this.lastTextSource = textSource;
if (this.options.selectMatchedText) {
textSource.select();
diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js
index 95762d5e..fc32a718 100644
--- a/ext/fg/js/frame.js
+++ b/ext/fg/js/frame.js
@@ -61,6 +61,37 @@ class Frame {
});
}
+ api_showTermGroupedDefs({definitions, options}) {
+ const sequence = ++this.sequence;
+ const context = {
+ definitions,
+ addable: options.ankiMethod !== 'disabled',
+ playback: options.enableAudioPlayback
+ };
+
+ this.definitions = definitions;
+ this.showSpinner(false);
+ window.scrollTo(0, 0);
+
+ renderText(context, 'term-list.html').then(content => {
+ $('.content').html(content);
+ $('.action-add-note').click(this.onAddNote.bind(this));
+
+ $('.kanji-link').click(e => {
+ e.preventDefault();
+ findKanji($(e.target).text()).then(kdefs => this.api_showKanjiDefs({options, definitions: kdefs}));
+ });
+
+ $('.action-play-audio').click(e => {
+ e.preventDefault();
+ const index = $(e.currentTarget).data('index');
+ this.playAudio(this.definitions[index]);
+ });
+
+ this.updateAddNoteButtons(['term_kanji', 'term_kana'], sequence);
+ });
+ }
+
api_showKanjiDefs({definitions, options}) {
const sequence = ++this.sequence;
const context = {
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 21f4a9d7..d2c78081 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -74,6 +74,10 @@ class Popup {
this.invokeApi('showTermDefs', {definitions, options});
}
+ showTermGroupedDefs(definitions, options) {
+ this.invokeApi('showTermGroupedDefs', {definitions, options});
+ }
+
showKanjiDefs(definitions, options) {
this.invokeApi('showKanjiDefs', {definitions, options});
}
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index aae044c5..cedfb887 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -41,6 +41,10 @@ function findTerm(text) {
return invokeBgApi('findTerm', {text});
}
+function findTermGrouped(text) {
+ return invokeBgApi('findTermGrouped', {text});
+}
+
function findKanji(text) {
return invokeBgApi('findKanji', {text});
}