diff options
| author | Marin Ivanov <[email protected]> | 2024-08-19 23:30:03 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-08-19 23:30:03 +0300 |
| commit | 08a1acccd6c6e6a11211b065a40629c08312686a (patch) | |
| tree | ada5e79462777a5eade461f263c86e96983269e2 /ka.js | |
| parent | 5ed74ed5cdfc9e286f4a2263a0cd022364b946a6 (diff) | |
improve loader
Diffstat (limited to 'ka.js')
| -rw-r--r-- | ka.js | 29 |
1 files changed, 12 insertions, 17 deletions
@@ -1,40 +1,35 @@ var doc = document; -var elAttr = (tag, name) => tag.getAttribute(name); -function el$Attr(name, value) { +var elproto = Element.prototype; +elproto.attr = function(name){ + return this.getAttribute(name); +}; +elproto.$attr = function(name, value) { this.setAttribute(name, value); return this; -} -function el$Attrs(attrs) { - for (const [attr, value] of Object.entries(attrs||{})) { +}; +elproto.$attrs = function(attrs) { + for (const [attr, value] of Object.entries(attrs)) { this.$attr(attr, value); } return this; } -function el$Cls(cls) { +elproto.$cls = function(cls) { return this.$attr("class", cls); } -function el$Value(value) { +elproto.$value = function(value) { this.value = value; return this; } -function el$Click(callback) { +elproto.$click = function(callback) { this.onclick = callback; return this; } function tag(name, attrs, ...children) { const el = doc.createElement(name); - el.attr = elAttr; - el.$attr = el$Attr; - el.$attrs = el$Attrs; - el.$cls = el$Cls; - el.$value = el$Value; - el.$click = el$Click; + el.$attrs(attrs||{}); for (const child of children) { el.appendChild((typeof(child) === 'string') ? doc.createTextNode(child) : child); } - for (const [attr, value] of Object.entries(attrs||{})) { - el.$attr(attr, value); - } return el; } |
