From 7165defd03c1e74e438355b32eac4ecab59496d5 Mon Sep 17 00:00:00 2001 From: Sergiusz Warga Date: Mon, 23 Nov 2020 02:44:15 +0100 Subject: [PATCH] Parsing Pensum to html and veryfing it works just fine --- app/templates/LLPSI/Pensum_cloze.html | 30 +++++++++++++++---- .../Pensa/01_Imperium_Romanum_Pensum_A | 2 +- .../Pensa/01_Imperium_Romanum_Pensum_A.html | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/templates/LLPSI/Pensum_cloze.html b/app/templates/LLPSI/Pensum_cloze.html index cccaef5..3328954 100644 --- a/app/templates/LLPSI/Pensum_cloze.html +++ b/app/templates/LLPSI/Pensum_cloze.html @@ -16,21 +16,41 @@ }); } + function mapper(char) { + var mapper = { 'A': 'Ā', + 'a': 'ā', + 'E': 'Ē', + 'e': 'ē', + 'I': 'Ī', + 'i': 'ī', + 'O': 'Ō', + 'o': 'ō', + 'U': 'Ū', + 'u': 'ū'}; + return mapper[char[0]]; + } + + function input_to_macron(input) { + return input.replace(/(\w)\1/, mapper); + } + function validate() { const forms = document.querySelectorAll('form'); const form = forms[0]; Array.from(form.elements).forEach((input) => { - console.log(input); - if (input.type=="text" && input.value != input.dataset.expected) { + 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", "border-color:red"); - console.log('incorrect!') + console.log('expected: ' + input.dataset.expected); + console.log('input: ' + input_to_macron(input.value)); + } else if (input.type=="text") { + input.setAttribute("style", "border-color:green"); } }); - console.log('dupa'); - return false; } diff --git a/app/templates/Pensa/01_Imperium_Romanum_Pensum_A b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A index 25b19de..df4cc7a 100644 --- a/app/templates/Pensa/01_Imperium_Romanum_Pensum_A +++ b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A @@ -1 +1 @@ -Ni-ilus fluvi_us_ est. Ni-ilus et Rhe-enus fluvi_i-i_ _sunt_, Cre-eta i-insul_a_ _est_. Cre-eta et Rhodus i-insul_ae_ sunt. Brundisium oppid_um_ _est_. Brundisium et Tu-usculum oppid_a_ sunt. \ No newline at end of file +Ni-ilus fluvi_us_ est. Ni-ilus et Rhe-enus fluvi_i-i_ _sunt_. Cre-eta i-insul_a_ _est_. Cre-eta et Rhodus i-insul_ae_ sunt. Brundisium oppid_um_ _est_. Brundisium et Tu-usculum oppid_a_ sunt. \ No newline at end of file diff --git a/app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html index 19ec91e..f6e4fb4 100644 --- a/app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html +++ b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html @@ -1 +1 @@ -Nīlus fluvi est. Nīlus et Rhēnus fluvi , Crēta īnsul . Crēta et Rhodus īnsul sunt. Brundisium oppid . Brundisium et Tūsculum oppid sunt. \ No newline at end of file +Nīlus fluvi est. Nīlus et Rhēnus fluvi . Crēta īnsul . Crēta et Rhodus īnsul sunt. Brundisium oppid . Brundisium et Tūsculum oppid sunt. \ No newline at end of file