From f89806e05d9db2924ee5bc80c6f640914d8ae2e5 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 1 Dec 2019 22:26:23 -0500 Subject: Simplify how anki errors are shown --- ext/bg/js/settings/anki.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/settings/anki.js b/ext/bg/js/settings/anki.js index b7fce011..68230139 100644 --- a/ext/bg/js/settings/anki.js +++ b/ext/bg/js/settings/anki.js @@ -31,13 +31,16 @@ function _ankiSpinnerShow(show) { } } -function _ankiErrorShow(error) { - const dialog = $('#anki-error'); +function _ankiSetError(error) { + const node = document.querySelector('#anki-error'); + if (!node) { return; } if (error) { - dialog.show().text(error); + node.hidden = false; + node.textContent = `${error}`; } else { - dialog.hide(); + node.hidden = true; + node.textContent = ''; } } @@ -119,9 +122,9 @@ async function _onAnkiModelChanged(e) { _ankiSpinnerShow(true); await _ankiFieldsPopulate(element, options); - _ankiErrorShow(); + _ankiSetError(null); } catch (error) { - _ankiErrorShow(error); + _ankiSetError(error); } finally { _ankiSpinnerShow(false); } @@ -131,7 +134,8 @@ async function _onAnkiModelChanged(e) { // Public function ankiErrorShown() { - return $('#anki-error').is(':visible'); + const node = document.querySelector('#anki-error'); + return node && !node.hidden; } function ankiFieldsToDict(selection) { @@ -212,10 +216,10 @@ async function onAnkiOptionsChanged(options) { try { _ankiSpinnerShow(true); await _ankiDeckAndModelPopulate(options); - _ankiErrorShow(); + _ankiSetError(null); _ankiDataPopulated = true; - } catch (e) { - _ankiErrorShow(e); + } catch (error) { + _ankiSetError(error); } finally { _ankiSpinnerShow(false); } -- cgit v1.2.3