From 78d5b511278cd9b8f9319220bec55b8628f6cb36 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 10 Feb 2017 20:45:01 -0800 Subject: fix url and sentence tags on kanji cards --- ext/fg/js/driver.js | 16 ++++++---------- ext/fg/js/frame.js | 31 +++++++++++++++++-------------- ext/fg/js/popup.js | 8 ++++---- 3 files changed, 27 insertions(+), 28 deletions(-) (limited to 'ext') diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index cb7f2ea6..c84805d7 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -143,13 +143,11 @@ class Driver { textSource.setEndOffset(length); const sentence = extractSentence(textSource, this.options.anki.sentenceExt); - definitions.forEach(definition => { - definition.url = window.location.href; - definition.sentence = sentence; - }); + const url = window.location.href; this.popup.showNextTo(textSource.getRect()); - this.popup.showTermDefs(definitions, this.options); + this.popup.showTermDefs(definitions, this.options, {sentence, url}); + this.lastTextSource = textSource; if (this.options.scanning.selectText) { textSource.select(); @@ -168,13 +166,11 @@ class Driver { return false; } else { const sentence = extractSentence(textSource, this.options.anki.sentenceExt); - definitions.forEach(definition => { - definition.url = window.location.href; - definition.sentence = sentence; - }); + const url = window.location.href; this.popup.showNextTo(textSource.getRect()); - this.popup.showKanjiDefs(definitions, this.options); + this.popup.showKanjiDefs(definitions, this.options, {sentence, url}); + this.lastTextSource = textSource; if (this.options.scanning.selectText) { textSource.select(); diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js index df8ca894..83d6d7ef 100644 --- a/ext/fg/js/frame.js +++ b/ext/fg/js/frame.js @@ -30,34 +30,32 @@ class Frame { }); } - api_showTermDefs({definitions, options}) { + api_showTermDefs({definitions, options, context}) { const sequence = ++this.sequence; - const context = { + const params = { definitions, grouped: options.general.groupResults, addable: options.ankiMethod !== 'disabled', playback: options.general.audioPlayback }; + definitions.forEach(definition => { + definition.sentence = context.sentence; + definition.url = context.url; + }); + this.definitions = definitions; this.showSpinner(false); window.scrollTo(0, 0); - renderText(context, 'terms.html').then(content => { + renderText(params, 'terms.html').then(content => { $('#content').html(content); $('.action-add-note').click(this.onAddNote.bind(this)); $('.kanji-link').click(e => { e.preventDefault(); const character = $(e.target).text(); - findKanji(character).then(kdefs => { - kdefs.forEach(kdef => { - kdef.url = definitions[0].url; - kdef.sentence = definitions[0].sentence; - }); - - this.api_showKanjiDefs({options, definitions: kdefs}); - }); + findKanji(character).then(definitions => this.api_showKanjiDefs({definitions, options, context})); }); $('.action-play-audio').click(e => { @@ -72,18 +70,23 @@ class Frame { }); } - api_showKanjiDefs({definitions, options}) { + api_showKanjiDefs({definitions, options, context}) { const sequence = ++this.sequence; - const context = { + const params = { definitions, addable: options.ankiMethod !== 'disabled' }; + definitions.forEach(definition => { + definition.sentence = context.sentence; + definition.url = context.url; + }); + this.definitions = definitions; this.showSpinner(false); window.scrollTo(0, 0); - renderText(context, 'kanji.html').then(content => { + renderText(params, 'kanji.html').then(content => { $('#content').html(content); $('.action-add-note').click(this.onAddNote.bind(this)); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 74e25c7d..751c6acc 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -68,12 +68,12 @@ class Popup { return this.container.style.visibility !== 'hidden'; } - showTermDefs(definitions, options) { - this.invokeApi('showTermDefs', {definitions, options}); + showTermDefs(definitions, options, context) { + this.invokeApi('showTermDefs', {definitions, options, context}); } - showKanjiDefs(definitions, options) { - this.invokeApi('showKanjiDefs', {definitions, options}); + showKanjiDefs(definitions, options, context) { + this.invokeApi('showKanjiDefs', {definitions, options, context}); } showOrphaned() { -- cgit v1.2.3