WIP
This commit is contained in:
parent
b1851c971c
commit
c5a7020e21
@ -37,7 +37,7 @@ function modelIdToFieldOptKey(id) {
|
|||||||
}[id];
|
}[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
function modelIdToTags(id) {
|
function modelIdToMarkers(id) {
|
||||||
return {
|
return {
|
||||||
'anki-term-model': ['audio', 'expression', 'glossary', 'glossary-list', 'reading', 'sentence', 'tags', 'url'],
|
'anki-term-model': ['audio', 'expression', 'glossary', 'glossary-list', 'reading', 'sentence', 'tags', 'url'],
|
||||||
'anki-kanji-model': ['character', 'glossary', 'glossary-list', 'kunyomi', 'onyomi', 'url'],
|
'anki-kanji-model': ['character', 'glossary', 'glossary-list', 'kunyomi', 'onyomi', 'url'],
|
||||||
@ -124,7 +124,7 @@ function populateAnkiFields(element, opts) {
|
|||||||
|
|
||||||
const modelId = element.attr('id');
|
const modelId = element.attr('id');
|
||||||
const optKey = modelIdToFieldOptKey(modelId);
|
const optKey = modelIdToFieldOptKey(modelId);
|
||||||
const tags = modelIdToTags(modelId);
|
const markers = modelIdToMarkers(modelId);
|
||||||
|
|
||||||
yomichan().api_getModelFieldNames({modelName, callback: (names) => {
|
yomichan().api_getModelFieldNames({modelName, callback: (names) => {
|
||||||
const table = element.closest('.tab-pane').find('.anki-fields');
|
const table = element.closest('.tab-pane').find('.anki-fields');
|
||||||
@ -135,19 +135,19 @@ function populateAnkiFields(element, opts) {
|
|||||||
const button = $('<button>', {type: 'button', class: 'btn btn-default dropdown-toggle'});
|
const button = $('<button>', {type: 'button', class: 'btn btn-default dropdown-toggle'});
|
||||||
button.attr('data-toggle', 'dropdown').dropdown();
|
button.attr('data-toggle', 'dropdown').dropdown();
|
||||||
|
|
||||||
const tagItems = $('<ul>', {class: 'dropdown-menu dropdown-menu-right'});
|
const markerItems = $('<ul>', {class: 'dropdown-menu dropdown-menu-right'});
|
||||||
for (const tag of tags) {
|
for (const marker of markers) {
|
||||||
const link = $('<a>', {href: '#'}).text(`{${tag}}`);
|
const link = $('<a>', {href: '#'}).text(`{${marker}}`);
|
||||||
link.click((e) => {
|
link.click((e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
link.closest('.input-group').find('.anki-field-value').val(link.text()).trigger('change');
|
link.closest('.input-group').find('.anki-field-value').val(link.text()).trigger('change');
|
||||||
});
|
});
|
||||||
tagItems.append($('<li>').append(link));
|
markerItems.append($('<li>').append(link));
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupBtn = $('<div>', {class: 'input-group-btn'});
|
const groupBtn = $('<div>', {class: 'input-group-btn'});
|
||||||
groupBtn.append(button.append($('<span>', {class: 'caret'})));
|
groupBtn.append(button.append($('<span>', {class: 'caret'})));
|
||||||
groupBtn.append(tagItems);
|
groupBtn.append(markerItems);
|
||||||
|
|
||||||
const group = $('<div>', {class: 'input-group'});
|
const group = $('<div>', {class: 'input-group'});
|
||||||
group.append($('<input>', {type: 'text', class: 'anki-field-value form-control', value: opts[optKey][name] || ''}).data('field', name).change(onOptionsAnkiChanged));
|
group.append($('<input>', {type: 'text', class: 'anki-field-value form-control', value: opts[optKey][name] || ''}).data('field', name).change(onOptionsAnkiChanged));
|
||||||
|
@ -19,21 +19,21 @@
|
|||||||
|
|
||||||
function sanitizeOptions(options) {
|
function sanitizeOptions(options) {
|
||||||
const defaults = {
|
const defaults = {
|
||||||
scanLength: 20,
|
scanLength: 20,
|
||||||
activateOnStartup: false,
|
activateOnStartup: false,
|
||||||
selectMatchedText: true,
|
selectMatchedText: true,
|
||||||
showAdvancedOptions: false,
|
showAdvancedOptions: false,
|
||||||
loadEnamDict: false,
|
loadEnamDict: false,
|
||||||
enableAudioPlayback: true,
|
enableAudioPlayback: true,
|
||||||
enableAnkiConnect: false,
|
enableAnkiConnect: false,
|
||||||
ankiCardTags: ['yomichan'],
|
ankiCardTags: ['yomichan'],
|
||||||
sentenceExtent: 200,
|
sentenceExtent: 200,
|
||||||
ankiTermDeck: options.ankiVocabDeck || '',
|
ankiTermDeck: options.ankiVocabDeck || '',
|
||||||
ankiTermModel: options.ankiVocabModel || '',
|
ankiTermModel: options.ankiVocabModel || '',
|
||||||
ankiTermFields: options.ankiVocabFields || {},
|
ankiTermFields: options.ankiVocabFields || {},
|
||||||
ankiKanjiDeck: '',
|
ankiKanjiDeck: '',
|
||||||
ankiKanjiModel: '',
|
ankiKanjiModel: '',
|
||||||
ankiKanjiFields: {}
|
ankiKanjiFields: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const key in defaults) {
|
for (const key in defaults) {
|
||||||
|
Loading…
Reference in New Issue
Block a user