V script.js dodajam dva primera, ki omogočita:

(a) izpolnjevanje ankete s pomočjo tipkovnice
	+ legende tipk

(b) primer poljubnega dinamičnega teksta kjerkoli v anketi
	(primer trenutnega meseca)

GLEJ main/survey/script.js
This commit is contained in:
May Doušak 2023-02-14 12:31:35 +01:00
parent 747a6834c9
commit 7d3a0a28f8

View File

@ -1954,3 +1954,82 @@ function disableSubsequentAnswers(){
});
}
// izpolnjevanje obrazcev s pomočjo tipk (0-9)
// enter submita formo (če seveda nisi noter v textu)!
$(document).on('keypress', function(e) {
var tag = e.target.tagName.toLowerCase();
if ( e.which >= 48 && e.which <= 57 && tag != 'input' && tag != 'textarea') {
var inputs = document.querySelectorAll('[data-calculation="' + (e.which-48) + '"]');
// delamo samo tam, kjer je le ena instanca tega!
if (inputs.length == 1) {
inputs[0].checked = true;
}
}
else if ( e.which === 13 && tag != 'input' && tag != 'textarea') {
var inputs = document.querySelectorAll('form[name="vnos"]');
if (inputs.length == 1) {
inputs[0].submit();
}
}
});
// doda labele pred radie (kaj pritisniti; veže se na zgornjo funkcionalnost)
// to bi morala biti generalna nastavitev ankete, tu je kot DEMO
$(document).ready(function() {
// extra: labele tipk (to bi dal opcijsko)
// samo tam, kjer je le en sklop
var en_sklop=1;
for (a=0; a<=9; a++) {
var inputs = document.querySelectorAll('[data-calculation="' + a + '"]');
if (inputs.length > 1) {
en_sklop=0;
}
}
if (en_sklop == 1) {
for (a=0; a<=9; a++) {
var inputs = document.querySelectorAll('[data-calculation="' + a + '"]');
if (inputs.length == 1) {
inputs[0].insertAdjacentHTML('afterend', '[' + a + ']');
}
}
}
});
// dodatno: primer, kako se lahko na ravni ankete zamenja tekst z nečim dinamičnim (iz ajaxa ali klienta)
/*
$(document).ready( function () {
const month = ["januarja","februarja","marca","aprila","maja","junija","julija","avgusta","septembra","oktobra","novembra","decembra"];
const d = new Date();
// create a TreeWalker of all text nodes
var allTextNodes = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT),
// some temp references for performance
tmptxt,
tmpnode,
// compile the RE and cache the replace string, for performance
cakeRE = /:trenutni_mesec:/g,
replaceValue = month[d.getMonth()];
// iterate through all text nodes
while (allTextNodes.nextNode()) {
tmpnode = allTextNodes.currentNode;
tmptxt = tmpnode.nodeValue;
tmpnode.nodeValue = tmptxt.replace(cakeRE, replaceValue);
}
});*/