summaryrefslogtreecommitdiffstats
path: root/nem/test/1/priprava.js
diff options
context:
space:
mode:
Diffstat (limited to 'nem/test/1/priprava.js')
-rw-r--r--nem/test/1/priprava.js96
1 files changed, 96 insertions, 0 deletions
diff --git a/nem/test/1/priprava.js b/nem/test/1/priprava.js
new file mode 100644
index 0000000..518406c
--- /dev/null
+++ b/nem/test/1/priprava.js
@@ -0,0 +1,96 @@
+document.addEventListener("DOMContentLoaded", () => {
+ pripraviDokument();
+});
+function pripraviDokument() {
+ var data;
+ try {
+ data = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
+ } catch (e) {
+ data = {vpr: []};
+ }
+ var el = document.getElementById("vpr");
+ el.innerHTML = "";
+ for (const vpr of data.vpr) {
+ var vprdiv = document.createElement("div");
+ vprdiv.classList = "vpr";
+ if (window.location.pathname.endsWith("priprava.html")) {
+ vprdiv.innerText = vpr.v+" ";
+ var odg = document.createElement("input");
+ odg.dataset.odg = vpr.o;
+ var odgspan = document.createElement("span");
+ odgspan.hidden = true;
+ odgspan.classList = "odgspan";
+ odgspan.innerText = " "+vpr.o;
+ vprdiv.appendChild(odg);
+ vprdiv.appendChild(odgspan);
+ } else {
+ var vprinput = document.createElement("input");
+ vprinput.value = vpr.v;
+ vprinput.onchange = naredichange;
+ var odg = document.createElement("input");
+ odg.value = vpr.o;
+ odg.onchange = naredichange;
+ vprdiv.appendChild(vprinput);
+ vprdiv.appendChild(odg)
+ }
+ el.appendChild(vprdiv);
+ }
+ if (window.location.pathname.endsWith("priprava.html")) {
+ document.getElementById("naredilink").href =
+ "naredi.html"+window.location.hash;
+ } else {
+ naredichange();
+ }
+}
+function preveri() {
+ var el = document.getElementById("stat");
+ var els = document.getElementsByClassName("vpr");
+ var richtig = 0;
+ var falsch = 0;
+ for (const vpr of els) {
+ var odg = vpr.children[0];
+ if (odg.dataset.odg.toLowerCase() == odg.value.toLowerCase()) {
+ odg.classList = "richtig";
+ richtig++;
+ } else {
+ odg.classList = "falsch";
+ falsch++;
+ }
+ }
+ el.innerText = richtig + "/" + (richtig+falsch) + " pravilnih";
+}
+function pokaziskrij() {
+ var els = document.getElementsByClassName("odgspan");
+ for (const el of els) {
+ el.hidden = !el.hidden;
+ }
+}
+
+function dodaj() {
+ var vprs = document.getElementById("vpr");
+ var div = document.createElement("div");
+ div.classList = "vpr";
+ var vpr = document.createElement("input");
+ vpr.onchange = naredichange;
+ var odg = document.createElement("input");
+ odg.onchange = naredichange;
+ div.appendChild(vpr);
+ div.appendChild(odg);
+ vprs.appendChild(div);
+}
+
+function naredichange() {
+ var vprs = document.getElementById("vpr").children;
+ data = {vpr: []};
+ for (const vpr of vprs) {
+ vprobj = {
+ v: vpr.children[0].value,
+ o: vpr.children[1].value
+ }
+ data.vpr.push(vprobj);
+ }
+ var datastr = (JSON.stringify(data));
+ document.getElementById("urejevalnik").href = "#"+datastr;
+ document.getElementById("vprasalnik").href = "priprava.html#"+datastr;
+ window.location.hash = "#"+datastr;
+}