This commit is contained in:
Alex Yatskov 2016-11-06 18:09:12 -08:00
parent 712cd6a9ab
commit 20304b5460
4 changed files with 27 additions and 17 deletions

View File

@ -154,17 +154,20 @@ function populateAnkiDeckAndModel(opts) {
}); });
} }
function populateDictionaries() { function populateDictionaries(opts) {
const container = $('.dictionaries'); const container = $('.dictionaries');
container.empty(); container.empty();
yomichan().translator.dictionary.getInfo().then(rows => { yomichan().translator.dictionary.getInfo().then(rows => {
rows.forEach(row => { rows.forEach(row => {
const dictOpts = opts.dictionaries[row.dictionary] || {enableTerms: true, enableKanji: false};
const html = Handlebars.templates['dictionary.html']({ const html = Handlebars.templates['dictionary.html']({
name: row.dictionary, name: row.dictionary,
version: row.version, version: row.version,
hasTerms: row.hasTerms, hasTerms: row.hasTerms,
hasKanji: row.hasKanji hasKanji: row.hasKanji,
enableTerms: dictOpts.enableTerms,
enableKanji: dictOpts.enableKanji
}); });
container.append($(html)); container.append($(html));
@ -276,7 +279,7 @@ $(document).ready(() => {
$('input, select').not('.anki-model').change(onOptionsChanged); $('input, select').not('.anki-model').change(onOptionsChanged);
$('.anki-model').change(onAnkiModelChanged); $('.anki-model').change(onAnkiModelChanged);
populateDictionaries(); populateDictionaries(opts);
populateAnkiDeckAndModel(opts); populateAnkiDeckAndModel(opts);
updateVisibility(opts); updateVisibility(opts);
}); });

View File

@ -28,6 +28,8 @@ function sanitizeOptions(options) {
scanDelay: 15, scanDelay: 15,
scanLength: 20, scanLength: 20,
dictionaries: {},
ankiMethod: 'disabled', ankiMethod: 'disabled',
ankiUsername: '', ankiUsername: '',
ankiPassword: '', ankiPassword: '',

View File

@ -1,9 +1,9 @@
(function() { (function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['dictionary.html'] = template({"1":function(container,depth0,helpers,partials,data) { templates['dictionary.html'] = template({"1":function(container,depth0,helpers,partials,data) {
return " <div class=\"checkbox\">\n <label><input type=\"checkbox\" class=\"dict-enable-terms\"> Enable term search</label>\n </div>\n"; return "disabled";
},"3":function(container,depth0,helpers,partials,data) { },"3":function(container,depth0,helpers,partials,data) {
return " <div class=\"checkbox\">\n <label><input type=\"checkbox\" class=\"dict-enable-kanji\"> Enable Kanji search</label>\n </div>\n"; return "checked";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
@ -13,10 +13,19 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
+ " <small>v." + " <small>v."
+ alias4(((helper = (helper = helpers.version || (depth0 != null ? depth0.version : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"version","hash":{},"data":data}) : helper))) + alias4(((helper = (helper = helpers.version || (depth0 != null ? depth0.version : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"version","hash":{},"data":data}) : helper)))
+ "</small></h4>\n </div>\n <div class=\"col-xs-4 text-right\">\n <button type=\"button\" class=\"dict-delete btn btn-danger\">Delete</button>\n </div>\n </div>\n\n" + "</small></h4>\n </div>\n <div class=\"col-xs-4 text-right\">\n <button type=\"button\" class=\"dict-delete btn btn-danger\">Delete</button>\n </div>\n </div>\n\n <div class=\"checkbox "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\">\n <label><input type=\"checkbox\" class=\"dict-enable-terms\" "
+ "</div>\n"; + ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.enableTerms : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "> Enable term search</label>\n </div>\n <div class=\"checkbox "
+ ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\">\n <label><input type=\"checkbox\" class=\"dict-enable-kanji\" "
+ ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.enableKanji : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "> Enable Kanji search</label>\n </div>\n</div>\n";
},"useData":true}); },"useData":true});
templates['footer.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { templates['footer.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var helper; var helper;

View File

@ -8,14 +8,10 @@
</div> </div>
</div> </div>
{{#if hasTerms}} <div class="checkbox {{#unless hasTerms}}disabled{{/unless}}">
<div class="checkbox"> <label><input type="checkbox" class="dict-enable-terms" {{#unless hasTerms}}disabled{{/unless}} {{#if enableTerms}}checked{{/if}}> Enable term search</label>
<label><input type="checkbox" class="dict-enable-terms"> Enable term search</label>
</div> </div>
{{/if}} <div class="checkbox {{#unless hasKanji}}disabled{{/unless}}">
{{#if hasKanji}} <label><input type="checkbox" class="dict-enable-kanji" {{#unless hasKanji}}disabled{{/unless}} {{#if enableKanji}}checked{{/if}}> Enable Kanji search</label>
<div class="checkbox">
<label><input type="checkbox" class="dict-enable-kanji"> Enable Kanji search</label>
</div> </div>
{{/if}}
</div> </div>