Anki: use CSS classes for term frequency color

This commit is contained in:
siikamiika 2017-10-24 12:49:10 +03:00
parent e034ca3ad4
commit 8400f0e4c0
2 changed files with 11 additions and 15 deletions

View File

@ -75,18 +75,6 @@ function handlebarsMultiLine(options) {
return options.fn(this).split('\n').join('<br>'); return options.fn(this).split('\n').join('<br>');
} }
function handlebarsTermFrequencyColor(options) {
const termFrequency = options.fn(this);
if (termFrequency === 'popular') {
return '#0275d8';
} else if (termFrequency === 'rare') {
return '#999';
} else {
return 'inherit';
}
}
function handlebarsRegisterHelpers() { function handlebarsRegisterHelpers() {
if (Handlebars.partials !== Handlebars.templates) { if (Handlebars.partials !== Handlebars.templates) {
Handlebars.partials = Handlebars.templates; Handlebars.partials = Handlebars.templates;
@ -95,7 +83,6 @@ function handlebarsRegisterHelpers() {
Handlebars.registerHelper('furiganaPlain', handlebarsFuriganaPlain); Handlebars.registerHelper('furiganaPlain', handlebarsFuriganaPlain);
Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks); Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks);
Handlebars.registerHelper('multiLine', handlebarsMultiLine); Handlebars.registerHelper('multiLine', handlebarsMultiLine);
Handlebars.registerHelper('termFrequencyColor', handlebarsTermFrequencyColor);
} }
} }

View File

@ -19,6 +19,15 @@
function optionsFieldTemplates() { function optionsFieldTemplates() {
return ` return `
<style>
.expression-popular {
color: #0275d8;
}
.expression-rare {
color: #999;
}
</style>
{{#*inline "glossary-single"}} {{#*inline "glossary-single"}}
{{~#unless brief~}} {{~#unless brief~}}
{{~#if definitionTags~}}<i>({{#each definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}} {{~#if definitionTags~}}<i>({{#each definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}}
@ -79,7 +88,7 @@ function optionsFieldTemplates() {
{{#*inline "furigana"}} {{#*inline "furigana"}}
{{~#if merge~}} {{~#if merge~}}
{{~#each definition.expressions~}} {{~#each definition.expressions~}}
<span style="color: {{#termFrequencyColor}}{{termFrequency}}{{/termFrequencyColor}}">{{~#furigana}}{{{.}}}{{/furigana~}}</span> <span class="expression-{{termFrequency}}">{{~#furigana}}{{{.}}}{{/furigana~}}</span>
{{~#unless @last}}{{/unless~}} {{~#unless @last}}{{/unless~}}
{{~/each~}} {{~/each~}}
{{~else~}} {{~else~}}
@ -90,7 +99,7 @@ function optionsFieldTemplates() {
{{#*inline "furigana-plain"}} {{#*inline "furigana-plain"}}
{{~#if merge~}} {{~#if merge~}}
{{~#each definition.expressions~}} {{~#each definition.expressions~}}
<span style="color: {{#termFrequencyColor}}{{termFrequency}}{{/termFrequencyColor}}">{{~#furiganaPlain}}{{{.}}}{{/furiganaPlain~}}</span> <span class="expression-{{termFrequency}}">{{~#furiganaPlain}}{{{.}}}{{/furiganaPlain~}}</span>
{{~#unless @last}}{{/unless~}} {{~#unless @last}}{{/unless~}}
{{~/each~}} {{~/each~}}
{{~else~}} {{~else~}}