diff options
| author | Marin Ivanov <[email protected]> | 2024-08-19 22:46:48 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-08-19 22:46:48 +0300 |
| commit | 5ed74ed5cdfc9e286f4a2263a0cd022364b946a6 (patch) | |
| tree | 330a71a652b1a35f22a60b7e4309b20693a9fa06 | |
| parent | c043207f57aa71fd9a89f31fee0e9756aad1a597 (diff) | |
wip: dynamic data
| -rw-r--r-- | index.html | 20 | ||||
| -rw-r--r-- | ka.js | 23 |
2 files changed, 37 insertions, 6 deletions
@@ -35,6 +35,7 @@ <script src="ka.js"></script> <script> const waiting = app.children[0]; + let isLoading = 0; const routes = { "/": () => div( h2("Lorem Ipsum"), @@ -47,8 +48,23 @@ p("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."), p("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "), ), - //"/network": () => div(), - //"/config": () => div(), + "/network": () => div( + isLoading ? waiting + : table( + tr( + td("IP"), + td(input("text").$value("127.0.0.1")), + ) + ).$cls("network"), + ), + "/config": () => { + isLoading = 1; + setTimeout(() => { + isLoading = 0; + app.reload(); + }, 10000); + return div(); + }, "/waiting": () => waiting, "": () => div( h1("Несъществуваща страница"), @@ -4,7 +4,20 @@ function el$Attr(name, value) { this.setAttribute(name, value); return this; } -function el$OnClick(callback) { +function el$Attrs(attrs) { + for (const [attr, value] of Object.entries(attrs||{})) { + this.$attr(attr, value); + } + return this; +} +function el$Cls(cls) { + return this.$attr("class", cls); +} +function el$Value(value) { + this.value = value; + return this; +} +function el$Click(callback) { this.onclick = callback; return this; } @@ -12,7 +25,10 @@ function tag(name, attrs, ...children) { const el = doc.createElement(name); el.attr = elAttr; el.$attr = el$Attr; - el.$onclick = el$OnClick; + el.$attrs = el$Attrs; + el.$cls = el$Cls; + el.$value = el$Value; + el.$click = el$Click; for (const child of children) { el.appendChild((typeof(child) === 'string') ? doc.createTextNode(child) : child); } @@ -22,13 +38,12 @@ function tag(name, attrs, ...children) { return el; } -const TRIVIAL = "h1,h2,h3,p,a,div,span,select"; +const TRIVIAL = "h1,h2,h3,p,a,div,span,select,table,tr,td"; for (let name of TRIVIAL.split(",")) { window[name] = (...children) => tag(name, null, ...children); } var ahref = (href, ...children) => tag("a", {href}, ...children); -var divcls = (klass, ...children) => tag("div", {class: klass}, ...children); var img = (src) => tag("img", {src}); var input = (type) => tag("input", {type}); |
