From 9ae5f4d33dbd9464bf7f4e35e5df530d9dc99720 Mon Sep 17 00:00:00 2001 From: nikeedev Date: Fri, 27 Sep 2024 12:30:36 +0200 Subject: [PATCH] up --- kefir.js | 33 ++++++++++++++++++++++++++++++--- test.html | 3 ++- test.js | 7 ++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/kefir.js b/kefir.js index 3114272..1c8e384 100644 --- a/kefir.js +++ b/kefir.js @@ -21,9 +21,11 @@ class Kefir { this.ui.forEach((elem, i) => { if (typeof elem === "string") { if (elem == "br") { - const br = document.createElement("br"); - root.appendChild(br); - } else if (elem.trimStart().startsWith("css:")) { + root.appendChild(document.createElement("br")); + } else if (elem == "hr") { + root.appendChild(document.createElement("hr")); + } + else if (elem.trimStart().startsWith("css:")) { const css = document.createElement("style"); css.innerHTML = elem.split("css:")[1].trim(); document.head.appendChild(css); @@ -107,6 +109,9 @@ class Kefir { case "img": case "image": const img = document.createElement("img"); + if (elem.id !== undefined && elem.id.trim() !== "") { + input.id = elem.id; + } try { img.src = elem.src; img.alt = elem.alt != "" ? elem.alt : ""; @@ -116,12 +121,34 @@ class Kefir { if (elem.height !== undefined) { img.height = elem.height; } + if (elem.action !== undefined) { + img.onclick = elem.action; + } } catch (e) { console.error(e); } root.appendChild(img); break; + case "input": + const input = document.createElement("input"); + if (elem.id !== undefined && elem.id.trim() !== "") { + input.id = elem.id; + } + try { + input.type = elem.input_type; + if (elem.placeholder != undefined) + input.placeholder = elem.placeholder; + + if (elem.action !== undefined) { + input.onchange = elem.action; + } + } catch (e) { + console.error(e); + } + root.appendChild(input); + break; + default: break; } diff --git a/test.html b/test.html index da6991e..56ab8a4 100644 --- a/test.html +++ b/test.html @@ -6,7 +6,8 @@ Kefir tests -
+
+
\ No newline at end of file diff --git a/test.js b/test.js index a367a95..7cb06fd 100644 --- a/test.js +++ b/test.js @@ -4,7 +4,6 @@ let button = localStorage.getItem("counter") || 0; const ui = [ "Hello", "br", - "br", { type: "button", text: "Increment: " + button, @@ -16,6 +15,7 @@ const ui = [ id: "incr" }, "br", + "br", { type: "button", text: "Clear", @@ -24,6 +24,11 @@ const ui = [ document.getElementById("incr").innerText = "Increment: " + button; localStorage.setItem("counter", button); } + }, + "hr", + { + type: "input", + input_type: "checkbox", } ]