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); textSource.setEndOffset(length);
const sentence = extractSentence(textSource, this.options.anki.sentenceExt); const sentence = extractSentence(textSource, this.options.anki.sentenceExt);
definitions.forEach(definition => { const url = window.location.href;
definition.url = window.location.href;
definition.sentence = sentence;
});
this.popup.showNextTo(textSource.getRect()); this.popup.showNextTo(textSource.getRect());
this.popup.showTermDefs(definitions, this.options); this.popup.showTermDefs(definitions, this.options, {sentence, url});
this.lastTextSource = textSource; this.lastTextSource = textSource;
if (this.options.scanning.selectText) { if (this.options.scanning.selectText) {
textSource.select(); textSource.select();
@ -168,13 +166,11 @@ class Driver {
return false; return false;
} else { } else {
const sentence = extractSentence(textSource, this.options.anki.sentenceExt); const sentence = extractSentence(textSource, this.options.anki.sentenceExt);
definitions.forEach(definition => { const url = window.location.href;
definition.url = window.location.href;
definition.sentence = sentence;
});
this.popup.showNextTo(textSource.getRect()); this.popup.showNextTo(textSource.getRect());
this.popup.showKanjiDefs(definitions, this.options); this.popup.showKanjiDefs(definitions, this.options, {sentence, url});
this.lastTextSource = textSource; this.lastTextSource = textSource;
if (this.options.scanning.selectText) { if (this.options.scanning.selectText) {
textSource.select(); textSource.select();

View File

@ -30,34 +30,32 @@ class Frame {
}); });
} }
api_showTermDefs({definitions, options}) { api_showTermDefs({definitions, options, context}) {
const sequence = ++this.sequence; const sequence = ++this.sequence;
const context = { const params = {
definitions, definitions,
grouped: options.general.groupResults, grouped: options.general.groupResults,
addable: options.ankiMethod !== 'disabled', addable: options.ankiMethod !== 'disabled',
playback: options.general.audioPlayback playback: options.general.audioPlayback
}; };
definitions.forEach(definition => {
definition.sentence = context.sentence;
definition.url = context.url;
});
this.definitions = definitions; this.definitions = definitions;
this.showSpinner(false); this.showSpinner(false);
window.scrollTo(0, 0); window.scrollTo(0, 0);
renderText(context, 'terms.html').then(content => { renderText(params, 'terms.html').then(content => {
$('#content').html(content); $('#content').html(content);
$('.action-add-note').click(this.onAddNote.bind(this)); $('.action-add-note').click(this.onAddNote.bind(this));
$('.kanji-link').click(e => { $('.kanji-link').click(e => {
e.preventDefault(); e.preventDefault();
const character = $(e.target).text(); const character = $(e.target).text();
findKanji(character).then(kdefs => { findKanji(character).then(definitions => this.api_showKanjiDefs({definitions, options, context}));
kdefs.forEach(kdef => {
kdef.url = definitions[0].url;
kdef.sentence = definitions[0].sentence;
});
this.api_showKanjiDefs({options, definitions: kdefs});
});
}); });
$('.action-play-audio').click(e => { $('.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 sequence = ++this.sequence;
const context = { const params = {
definitions, definitions,
addable: options.ankiMethod !== 'disabled' addable: options.ankiMethod !== 'disabled'
}; };
definitions.forEach(definition => {
definition.sentence = context.sentence;
definition.url = context.url;
});
this.definitions = definitions; this.definitions = definitions;
this.showSpinner(false); this.showSpinner(false);
window.scrollTo(0, 0); window.scrollTo(0, 0);
renderText(context, 'kanji.html').then(content => { renderText(params, 'kanji.html').then(content => {
$('#content').html(content); $('#content').html(content);
$('.action-add-note').click(this.onAddNote.bind(this)); $('.action-add-note').click(this.onAddNote.bind(this));

View File

@ -68,12 +68,12 @@ class Popup {
return this.container.style.visibility !== 'hidden'; return this.container.style.visibility !== 'hidden';
} }
showTermDefs(definitions, options) { showTermDefs(definitions, options, context) {
this.invokeApi('showTermDefs', {definitions, options}); this.invokeApi('showTermDefs', {definitions, options, context});
} }
showKanjiDefs(definitions, options) { showKanjiDefs(definitions, options, context) {
this.invokeApi('showKanjiDefs', {definitions, options}); this.invokeApi('showKanjiDefs', {definitions, options, context});
} }
showOrphaned() { showOrphaned() {