From 98d22a92f33e50d6c75df08be70cf801610b4fb7 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 12 Jun 2017 22:58:02 -0700 Subject: prepare ui for zip dictionaries --- ext/bg/js/options.js | 69 +++++++++++++++++++--------------------------------- ext/bg/options.html | 17 ++----------- 2 files changed, 27 insertions(+), 59 deletions(-) diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index c3321012..0b8b7ac3 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -140,9 +140,7 @@ $(document).ready(() => { $('#scan-modifier-key').val(options.scanning.modifier); $('#dict-purge').click(onDictionaryPurge); - $('#dict-importer a').click(onDictionarySetUrl); - $('#dict-import').click(onDictionaryImport); - $('#dict-url').on('input', onDictionaryUpdateUrl); + $('#dict-file').change(onDictionaryImport); $('#anki-enable').prop('checked', options.anki.enable); $('#card-tags').val(options.anki.tags.join(' ')); @@ -253,49 +251,32 @@ function onDictionaryPurge(e) { } function onDictionaryImport() { - dictionaryErrorShow(null); - dictionarySpinnerShow(true); - - const dictUrl = $('#dict-url'); - const dictImporter = $('#dict-importer').hide(); - const dictProgress = $('#dict-import-progress').show(); - const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`); - - setProgress(0.0); - - optionsLoad().then(options => { - instDb().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => { - options.dictionaries[summary.title] = {enabled: true, priority: 0}; - return optionsSave(options); - }).then(() => dictionaryGroupsPopulate(options)).catch(dictionaryErrorShow).then(() => { - dictionarySpinnerShow(false); - dictProgress.hide(); - dictImporter.show(); - dictUrl.val(''); - dictUrl.trigger('input'); - }); - }); -} - -function onDictionarySetUrl(e) { - e.preventDefault(); - - const dictUrl = $('#dict-url'); - const url = $(this).data('url'); - if (url.includes('/')) { - dictUrl.val(url); - } else { - dictUrl.val(chrome.extension.getURL(`bg/lang/dict/${url}/index.json`)); - } - - dictUrl.trigger('input'); -} - -function onDictionaryUpdateUrl() { - $('#dict-import').prop('disabled', $(this).val().length === 0); + alert('import'); + + // dictionaryErrorShow(null); + // dictionarySpinnerShow(true); + + // const dictUrl = $('#dict-url'); + // const dictImporter = $('#dict-importer').hide(); + // const dictProgress = $('#dict-import-progress').show(); + // const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`); + + // setProgress(0.0); + + // optionsLoad().then(options => { + // instDb().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => { + // options.dictionaries[summary.title] = {enabled: true, priority: 0}; + // return optionsSave(options); + // }).then(() => dictionaryGroupsPopulate(options)).catch(dictionaryErrorShow).then(() => { + // dictionarySpinnerShow(false); + // dictProgress.hide(); + // dictImporter.show(); + // dictUrl.val(''); + // dictUrl.trigger('input'); + // }); + // }); } - /* * Anki */ diff --git a/ext/bg/options.html b/ext/bg/options.html index 6a359f5e..aebf1ffd 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -145,21 +145,8 @@ -
- - -
- -
+
+
-- cgit v1.2.3