diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-01 22:16:58 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-01 22:16:58 -0500 |
commit | b4cdbf0263d270cf227490771bdff8ed2882fd9f (patch) | |
tree | e9951c7a2ba13c64ae83e4c13d92b35c05de76d8 /ext/bg/js/settings/anki.js | |
parent | 3e1b080cd3f0846f623f6bcf186581ac27998256 (diff) |
Update how anki settings are updated
Diffstat (limited to 'ext/bg/js/settings/anki.js')
-rw-r--r-- | ext/bg/js/settings/anki.js | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/ext/bg/js/settings/anki.js b/ext/bg/js/settings/anki.js index ae380fdb..aa89c6bf 100644 --- a/ext/bg/js/settings/anki.js +++ b/ext/bg/js/settings/anki.js @@ -17,6 +17,9 @@ */ +let _ankiDataPopulated = false; + + function ankiSpinnerShow(show) { const spinner = $('#anki-spinner'); if (show) { @@ -165,11 +168,7 @@ function onAnkiMarkerClicked(e) { async function onAnkiModelChanged(e) { try { - if (!e.originalEvent) { - return; - } - - const element = $(this); + const element = $(e.currentTarget); const tab = element.closest('.tab-pane'); const tabId = tab.attr('id'); @@ -188,3 +187,30 @@ async function onAnkiModelChanged(e) { ankiSpinnerShow(false); } } + + +function ankiInitialize() { + for (const node of document.querySelectorAll('#anki-terms-model,#anki-kanji-model')) { + node.addEventListener('change', (e) => onAnkiModelChanged(e), false); + } +} + +async function onAnkiOptionsChanged(options) { + if (!options.anki.enable) { + _ankiDataPopulated = false; + return; + } + + if (_ankiDataPopulated) { return; } + + try { + ankiSpinnerShow(true); + await ankiDeckAndModelPopulate(options); + ankiErrorShow(); + _ankiDataPopulated = true; + } catch (e) { + ankiErrorShow(e); + } finally { + ankiSpinnerShow(false); + } +} |