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 /ka.js | |
| parent | c043207f57aa71fd9a89f31fee0e9756aad1a597 (diff) | |
wip: dynamic data
Diffstat (limited to 'ka.js')
| -rw-r--r-- | ka.js | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -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}); |
