From 093fa3a43729a789bf31568405166770fcca2ad9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 1 Dec 2019 22:21:10 -0500 Subject: [PATCH] Group public/private functions together --- ext/bg/js/settings/anki.js | 132 +++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 63 deletions(-) diff --git a/ext/bg/js/settings/anki.js b/ext/bg/js/settings/anki.js index 0a75d229..b7fce011 100644 --- a/ext/bg/js/settings/anki.js +++ b/ext/bg/js/settings/anki.js @@ -17,6 +17,8 @@ */ +// Private + let _ankiDataPopulated = false; @@ -39,19 +41,6 @@ function _ankiErrorShow(error) { } } -function ankiErrorShown() { - return $('#anki-error').is(':visible'); -} - -function ankiFieldsToDict(selection) { - const result = {}; - selection.each((index, element) => { - result[$(element).data('field')] = $(element).val(); - }); - - return result; -} - async function _ankiDeckAndModelPopulate(options) { const ankiFormat = $('#anki-format').hide(); @@ -89,56 +78,6 @@ function _ankiCreateFieldTemplate(name, value, markers) { return content; } -function ankiGetFieldMarkersHtml(markers, fragment) { - const template = document.querySelector('#anki-field-marker-template').content; - if (!fragment) { - fragment = new DocumentFragment(); - } - for (const marker of markers) { - const markerNode = document.importNode(template, true).firstChild; - markerNode.querySelector('.marker-link').textContent = marker; - fragment.appendChild(markerNode); - } - return fragment; -} - -function ankiGetFieldMarkers(type) { - switch (type) { - case 'terms': - return [ - 'audio', - 'cloze-body', - 'cloze-prefix', - 'cloze-suffix', - 'dictionary', - 'expression', - 'furigana', - 'furigana-plain', - 'glossary', - 'glossary-brief', - 'reading', - 'screenshot', - 'sentence', - 'tags', - 'url' - ]; - case 'kanji': - return [ - 'character', - 'dictionary', - 'glossary', - 'kunyomi', - 'onyomi', - 'screenshot', - 'sentence', - 'tags', - 'url' - ]; - default: - return []; - } -} - async function _ankiFieldsPopulate(element, options) { const modelName = element.val(); if (!modelName) { @@ -189,6 +128,73 @@ async function _onAnkiModelChanged(e) { } +// Public + +function ankiErrorShown() { + return $('#anki-error').is(':visible'); +} + +function ankiFieldsToDict(selection) { + const result = {}; + selection.each((index, element) => { + result[$(element).data('field')] = $(element).val(); + }); + + return result; +} + + +function ankiGetFieldMarkersHtml(markers, fragment) { + const template = document.querySelector('#anki-field-marker-template').content; + if (!fragment) { + fragment = new DocumentFragment(); + } + for (const marker of markers) { + const markerNode = document.importNode(template, true).firstChild; + markerNode.querySelector('.marker-link').textContent = marker; + fragment.appendChild(markerNode); + } + return fragment; +} + +function ankiGetFieldMarkers(type) { + switch (type) { + case 'terms': + return [ + 'audio', + 'cloze-body', + 'cloze-prefix', + 'cloze-suffix', + 'dictionary', + 'expression', + 'furigana', + 'furigana-plain', + 'glossary', + 'glossary-brief', + 'reading', + 'screenshot', + 'sentence', + 'tags', + 'url' + ]; + case 'kanji': + return [ + 'character', + 'dictionary', + 'glossary', + 'kunyomi', + 'onyomi', + 'screenshot', + 'sentence', + 'tags', + 'url' + ]; + default: + return []; + } +} + + function ankiInitialize() { for (const node of document.querySelectorAll('#anki-terms-model,#anki-kanji-model')) { node.addEventListener('change', (e) => _onAnkiModelChanged(e), false);