Group public/private functions together

This commit is contained in:
toasted-nutbread 2019-12-01 22:21:10 -05:00
parent 4f7fa8474d
commit 093fa3a437

View File

@ -17,6 +17,8 @@
*/ */
// Private
let _ankiDataPopulated = false; 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) { async function _ankiDeckAndModelPopulate(options) {
const ankiFormat = $('#anki-format').hide(); const ankiFormat = $('#anki-format').hide();
@ -89,56 +78,6 @@ function _ankiCreateFieldTemplate(name, value, markers) {
return content; 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) { async function _ankiFieldsPopulate(element, options) {
const modelName = element.val(); const modelName = element.val();
if (!modelName) { 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() { function ankiInitialize() {
for (const node of document.querySelectorAll('#anki-terms-model,#anki-kanji-model')) { for (const node of document.querySelectorAll('#anki-terms-model,#anki-kanji-model')) {
node.addEventListener('change', (e) => _onAnkiModelChanged(e), false); node.addEventListener('change', (e) => _onAnkiModelChanged(e), false);