From 20304b5460e54621511a98b9dba9236d4d192ac3 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 18:09:12 -0800 Subject: [PATCH] WIP --- ext/bg/js/options-form.js | 9 ++++++--- ext/bg/js/options.js | 2 ++ ext/bg/js/templates.js | 21 +++++++++++++++------ tmpl/dictionary.html | 12 ++++-------- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 98ec15a3..3ea850b7 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -154,17 +154,20 @@ function populateAnkiDeckAndModel(opts) { }); } -function populateDictionaries() { +function populateDictionaries(opts) { const container = $('.dictionaries'); container.empty(); yomichan().translator.dictionary.getInfo().then(rows => { rows.forEach(row => { + const dictOpts = opts.dictionaries[row.dictionary] || {enableTerms: true, enableKanji: false}; const html = Handlebars.templates['dictionary.html']({ name: row.dictionary, version: row.version, hasTerms: row.hasTerms, - hasKanji: row.hasKanji + hasKanji: row.hasKanji, + enableTerms: dictOpts.enableTerms, + enableKanji: dictOpts.enableKanji }); container.append($(html)); @@ -276,7 +279,7 @@ $(document).ready(() => { $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); - populateDictionaries(); + populateDictionaries(opts); populateAnkiDeckAndModel(opts); updateVisibility(opts); }); diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 15288afc..28448b96 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -28,6 +28,8 @@ function sanitizeOptions(options) { scanDelay: 15, scanLength: 20, + dictionaries: {}, + ankiMethod: 'disabled', ankiUsername: '', ankiPassword: '', diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 7e78db3b..fe4d95ca 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -1,9 +1,9 @@ (function() { var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; templates['dictionary.html'] = template({"1":function(container,depth0,helpers,partials,data) { - return "
\n \n
\n"; + return "disabled"; },"3":function(container,depth0,helpers,partials,data) { - return "
\n \n
\n"; + return "checked"; },"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; @@ -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))) + " 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))) - + "\n \n
\n \n
\n \n\n" - + ((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["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"; + + "\n \n
\n \n
\n \n\n
\n \n
\n
\n \n
\n\n"; },"useData":true}); templates['footer.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { var helper; diff --git a/tmpl/dictionary.html b/tmpl/dictionary.html index 21847722..77493d94 100644 --- a/tmpl/dictionary.html +++ b/tmpl/dictionary.html @@ -8,14 +8,10 @@ - {{#if hasTerms}} -
- +
+
- {{/if}} - {{#if hasKanji}} -
- +
+
- {{/if}}