fix url and sentence tags on kanji cards

This commit is contained in:
Alex Yatskov 2017-02-10 20:45:01 -08:00
parent caa09c63a1
commit 78d5b51127
3 changed files with 27 additions and 28 deletions

View File

@ -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();

View File

@ -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));

View File

@ -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() {