This commit is contained in:
Alex Yatskov 2016-05-22 20:51:06 -07:00
parent bd17b05eef
commit e7b6b171cb
3 changed files with 23 additions and 13 deletions

View File

@ -22,20 +22,28 @@ function yomichan() {
} }
function optionsToForm(opts) { function optionsToForm(opts) {
$('#activate-on-startup').prop('checked', opts.activateOnStartup);
$('#enable-anki-connect').prop('checked', opts.enableAnkiConnect);
$('#load-enamdict').prop('checked', opts.loadEnamDict);
$('#scan-length').val(opts.scanLength); $('#scan-length').val(opts.scanLength);
$('#activate-on-startup').prop('checked', opts.activateOnStartup);
$('#load-enamdict').prop('checked', opts.loadEnamDict);
$('#select-matched-text').prop('checked', opts.selectMatchedText); $('#select-matched-text').prop('checked', opts.selectMatchedText);
$('#enable-anki-connect').prop('checked', opts.enableAnkiConnect);
$('#anki-vocab-deck').val(opts.ankiVocabDeck);
$('#anki-vocab-model').val(opts.ankiVocabModel);
$('#anki-kanji-deck').val(opts.ankiKanjiDeck);
$('#anki-kanji-model').val(opts.ankiKanjiModel);
} }
function formToOptions() { function formToOptions() {
return sanitizeOptions({ return sanitizeOptions({
activateOnStartup: $('#activate-on-startup').prop('checked'),
enableAnkiConnect: $('#enable-anki-connect').prop('checked'),
loadEnamDict: $('#load-enamdict').prop('checked'),
scanLength: $('#scan-length').val(), scanLength: $('#scan-length').val(),
selectMatchedText: $('#select-matched-text').prop('checked') activateOnStartup: $('#activate-on-startup').prop('checked'),
loadEnamDict: $('#load-enamdict').prop('checked'),
selectMatchedText: $('#select-matched-text').prop('checked'),
enableAnkiConnect: $('#enable-anki-connect').prop('checked'),
ankiVocabDeck: $('#anki-vocab-deck').val(),
ankiVocabModel: $('#anki-vocab-model').val(),
ankiKanjiDeck: $('#anki-kanji-deck').val(),
ankiKanjiModel: $('#anki-kanji-model').val()
}); });
} }
@ -104,7 +112,7 @@ $(document).ready(() => {
loadOptions((opts) => { loadOptions((opts) => {
optionsToForm(opts); optionsToForm(opts);
$('input').on('input paste change', onOptionsChanged); $('input, select').on('input paste change', onOptionsChanged);
$('.anki-model').change(onModelChanged); $('.anki-model').change(onModelChanged);
updateAnkiFormVis(opts); updateAnkiFormVis(opts);

View File

@ -19,14 +19,16 @@
function sanitizeOptions(options) { function sanitizeOptions(options) {
const defaults = { const defaults = {
activateOnStartup: false,
loadEnamDict: false,
scanLength: 20, scanLength: 20,
activateOnStartup: false,
selectMatchedText: true, selectMatchedText: true,
loadEnamDict: false,
enableAnkiConnect: false, enableAnkiConnect: false,
ankiDeck: '', ankiVocabDeck: '',
ankiModel: '', ankiVocabModel: '',
ankiVocabFields: {}, ankiVocabFields: {},
ankiKanjiDeck: '',
ankiKanjiModel: '',
ankiKanjiFields: {} ankiKanjiFields: {}
}; };

View File

@ -119,7 +119,7 @@
</div> </div>
</div> </div>
<table class="table table-bordered ankiFields"> <table class="table table-bordered anki-fields">
<thead> <thead>
<tr> <tr>
<th>Field</th> <th>Field</th>