From fd6622400f64b2d568d38bde72f9fd75f8d06beb Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 17:10:31 -0800 Subject: Templates --- tmpl/dictionary.html | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tmpl/dictionary.html (limited to 'tmpl') diff --git a/tmpl/dictionary.html b/tmpl/dictionary.html new file mode 100644 index 00000000..21847722 --- /dev/null +++ b/tmpl/dictionary.html @@ -0,0 +1,21 @@ +
+
+
+

{{name}} v.{{version}}

+
+
+ +
+
+ + {{#if hasTerms}} +
+ +
+ {{/if}} + {{#if hasKanji}} +
+ +
+ {{/if}} +
-- cgit v1.2.3 From 712cd6a9ab4e627e3c1504740ff853a6d12025f4 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 17:56:47 -0800 Subject: Simplify field code --- ext/bg/js/options-form.js | 56 ++++++++++++++++------------------------------- ext/bg/js/templates.js | 17 ++++++++++++++ tmpl/model.html | 18 +++++++++++++++ 3 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 tmpl/model.html (limited to 'tmpl') diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index ec603eed..98ec15a3 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -155,11 +155,11 @@ function populateAnkiDeckAndModel(opts) { } function populateDictionaries() { - const dictGroups = $('.dictionaries'); - dictGroups.empty(); + const container = $('.dictionaries'); + container.empty(); yomichan().translator.dictionary.getInfo().then(rows => { - for (const row of rows) { + rows.forEach(row => { const html = Handlebars.templates['dictionary.html']({ name: row.dictionary, version: row.version, @@ -167,14 +167,15 @@ function populateDictionaries() { hasKanji: row.hasKanji }); - dictGroups.append($(html)); - } + container.append($(html)); + }); }); } function populateAnkiFields(element, opts) { - const table = element.closest('.tab-pane').find('.anki-fields'); - table.find('tbody').remove(); + const tab = element.closest('.tab-pane'); + const container = tab.find('.anki-fields tbody'); + container.empty(); const modelName = element.val(); if (modelName === null) { @@ -186,41 +187,22 @@ function populateAnkiFields(element, opts) { const markers = modelIdToMarkers(modelId); return anki().getModelFieldNames(modelName).then(names => { - const tbody = $(''); names.forEach(name => { - const button = $('\n \n \n \n \n\n"; +},"useData":true}); templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; diff --git a/tmpl/model.html b/tmpl/model.html new file mode 100644 index 00000000..94772316 --- /dev/null +++ b/tmpl/model.html @@ -0,0 +1,18 @@ + + {{name}} + +
+ +
+ + +
+
+ + -- cgit v1.2.3 From 20304b5460e54621511a98b9dba9236d4d192ac3 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 18:09:12 -0800 Subject: 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(-) (limited to 'tmpl') 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}}
-- cgit v1.2.3 From 7fa51d682f29fbf51ed1228ca8840ff60be48e5e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 18:58:00 -0800 Subject: More work on options --- ext/bg/js/options-form.js | 23 ++++++++++++++++++++--- ext/bg/js/templates.js | 2 +- ext/bg/options.html | 16 ++++++++-------- tmpl/dictionary.html | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-) (limited to 'tmpl') diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index f9346d7d..9919031a 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -91,7 +91,7 @@ function getFormValues() { optsNew.ankiKanjiModel = $('#anki-kanji-model').val(); optsNew.ankiKanjiFields = fieldsToDict($('#kanji .anki-field-value')); - $('.dictionary').each((index, element) => { + $('.dict').each((index, element) => { const dictionary = $(element); const name = dictionary.data('name'); const enableTerms = dictionary.find('.dict-enable-terms').prop('checked'); @@ -163,7 +163,7 @@ function populateAnkiDeckAndModel(opts) { } function populateDictionaries(opts) { - const container = $('.dictionaries'); + const container = $('.dicts'); container.empty(); yomichan().translator.dictionary.getInfo().then(rows => { @@ -181,7 +181,7 @@ function populateDictionaries(opts) { container.append($(html)); }); - container.find('.dictionary input').change(onOptionsChanged); + container.find('.dict input').change(onOptionsChanged); }); } @@ -289,6 +289,23 @@ $(document).ready(() => { $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); + $('#dict-import a').click(e => { + e.preventDefault(); + const control = $('#dict-import-url'); + const url = $(e.target).data('url'); + if (url.includes('/')) { + control.val(url); + } else { + control.val(chrome.extension.getURL(`bg/data/${url}`)); + } + control.trigger('change'); + }); + + $('#dict-import-url').on('change keyup paste', () => { + const disable = $('#dict-import-url').val().trim().length === 0; + $('#dict-import-start').prop('disabled', disable); + }); + populateDictionaries(opts); populateAnkiDeckAndModel(opts); updateVisibility(opts); diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index fe4d95ca..2caf6ba8 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -7,7 +7,7 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p },"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; - return "
\n
\n
\n

" + 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))) diff --git a/ext/bg/options.html b/ext/bg/options.html index bc87d654..800fe8e9 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -6,7 +6,7 @@