latin/app/templates/LLPSI/Pensum_cloze.html

66 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="la">
<head>
<meta charset="UTF-8">
<title>Familia Romana Pensum A</title>
<script type="text/javascript">
function adjust_size() {
const forms = document.querySelectorAll('form');
const form = forms[0];
console.log('dupa');
Array.from(form.elements).forEach((input) => {
if (input.type=="text") {
input.setAttribute("size", input.dataset.expected.length + 1);
}
});
}
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) => {
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('expected: ' + input.dataset.expected);
console.log('input: ' + input_to_macron(input.value));
} else if (input.type=="text") {
input.setAttribute("style", "border-color:green");
}
});
return false;
}
</script>
</head>
<body>
<form class="Pensum_A" onsubmit="return validate();">
{{pensum_content|safe}}
<br>
<input type="submit" value="Submit">
</form>
<script type="text/javascript">adjust_size();</script>
</body>
</html>