diff --git a/app/templates/LLPSI/Pensum_cloze.html b/app/templates/LLPSI/Pensum_cloze.html index 6c03082..a73587f 100644 --- a/app/templates/LLPSI/Pensum_cloze.html +++ b/app/templates/LLPSI/Pensum_cloze.html @@ -10,13 +10,12 @@ Array.from(form.elements).forEach((input) => { if (input.type=="text") { - console.log(input.dataset.expected.length) input.setAttribute("style", input.getAttribute("style") + "; width: " + input.dataset.expected.length + "em"); } }); } - function mapper(char) { + function nomacron_to_macron(char) { var mapper = { 'A': 'Ā', 'a': 'ā', 'E': 'Ē', @@ -30,22 +29,45 @@ return mapper[char[0]]; } - function input_to_macron(input) { - return input.replace(/(\w)\1/, mapper); + function macron_to_nomacron(char) { + var mapper = { 'Ā': 'A', + 'ā': 'a', + 'Ē': 'E', + 'ē': 'e', + 'Ī': 'I', + 'ī': 'i', + 'Ō': 'O', + 'ō': 'o', + 'Ū': 'U', + 'ū': 'u'}; + return mapper[char]; } + function input_to_nomacron(input) { + return input.replace(/Ā|ā|Ē|ē|Ī|ī/, macron_to_nomacron); + } + + function input_to_macron(input) { + return input.replace(/(\w)\1/, nomacron_to_macron); + } + + function validate() { const forms = document.querySelectorAll('form'); const form = forms[0]; Array.from(form.elements).forEach((input) => { - is_double_ok = (input_to_macron(input.value) == input.dataset.expected); - is_macron_ok = (input.value == input.dataset.expected); + if (input.type=="text" && document.getElementById('vowel_length').checked == false) { + is_macron_ok = (input.value == input_to_nomacron(input.dataset.expected)); + console.log(input_to_nomacron(input.dataset.expected)); + is_double_ok = false; + } else { + is_double_ok = (input_to_macron(input.value) == input.dataset.expected); + is_macron_ok = (input.value == input.dataset.expected); + } if (input.type=="text" && !(is_double_ok || is_macron_ok)) { input.setAttribute("style", input.getAttribute("style") + "; border-color:red"); - console.log('expected: ' + input.dataset.expected); - console.log('input: ' + input_to_macron(input.value)); } else if (input.type=="text") { input.setAttribute("style", input.getAttribute("style") + "; border-color:green"); } @@ -69,6 +91,7 @@