From 7d3a0a28f8af4f25b8bc09f24953998ab0282d93 Mon Sep 17 00:00:00 2001 From: MAY Date: Tue, 14 Feb 2023 12:31:35 +0100 Subject: [PATCH] =?UTF-8?q?V=20script.js=20dodajam=20dva=20primera,=20ki?= =?UTF-8?q?=20omogo=C4=8Dita:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (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 --- main/survey/js/script.js | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/main/survey/js/script.js b/main/survey/js/script.js index 8b4434d90..cb053688e 100644 --- a/main/survey/js/script.js +++ b/main/survey/js/script.js @@ -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); + } +});*/ \ No newline at end of file