fix anki network error dialog on search page, cleanup template

workaround
This commit is contained in:
Alex Yatskov 2017-08-18 21:14:09 -07:00
parent 922d2cd468
commit 30fe3d2506
3 changed files with 22 additions and 18 deletions

View File

@ -66,6 +66,9 @@ async function apiDefinitionAdd(definition, mode) {
}
async function apiDefinitionsAddable(definitions, modes) {
const states = [];
try {
const notes = [];
for (const definition of definitions) {
for (const mode of modes) {
@ -74,7 +77,6 @@ async function apiDefinitionsAddable(definitions, modes) {
}
const results = await utilBackend().anki.canAddNotes(notes);
const states = [];
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
const state = {};
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
@ -84,6 +86,11 @@ async function apiDefinitionsAddable(definitions, modes) {
states.push(state);
}
return states;
} catch (e) {
// NOP
}
return states;
}

View File

@ -223,10 +223,7 @@ function dictFieldFormat(field, definition, mode, options) {
modeKanji: mode === 'kanji'
};
field = field.replace(
`{${marker}}`,
handlebarsRender('fields.html', data).trim()
);
field = field.replace(`{${marker}}`, handlebarsRender('fields.html', data));
}
return field;

View File

@ -51,5 +51,5 @@ function handlebarsRender(template, data) {
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
}
return Handlebars.templates[template](data);
return Handlebars.templates[template](data).trim();
}