summaryrefslogtreecommitdiff
path: root/web/static
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-09 18:02:30 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-09 18:09:24 -0700
commitc227fb7cc9e30d6a4330cdad34b0b2a53b014d93 (patch)
tree4d5f6f4bfcb15e67de4bb588334f3b7facf86aa4 /web/static
parent9ba644fd849ef7664be009e00206bf5eb1b85762 (diff)
downloaddartboat-c227fb7cc9e30d6a4330cdad34b0b2a53b014d93.tar.gz
dartboat-c227fb7cc9e30d6a4330cdad34b0b2a53b014d93.tar.xz
web: add support for child DOM elements and text nodes
Diffstat (limited to 'web/static')
-rw-r--r--web/static/dartboat.js40
1 files changed, 29 insertions, 11 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js
index eb1b8fa..e664a8d 100644
--- a/web/static/dartboat.js
+++ b/web/static/dartboat.js
@@ -55,18 +55,29 @@ function elemScrollToBottom(sel) {
e.scrollTop = e.scrollHeight;
}
-function elemAppendElemv(sel, elemc, elemv, off_ns, off_name, off_content,
- off_n_attrs, off_attr_names, off_attr_vals) {
- const target = $(UTF8ToString(sel));
-
+function targetAppendElemv(target, elemc, elemv,
+ off_type, off_ns, off_name, off_content,
+ off_n_attrs, off_attr_names, off_attr_vals,
+ off_n_children, off_children) {
for (let ptr = elemv; ptr < elemv + 4*elemc; ptr += 4) {
const struct = HEAP32[ptr>>2];
- const nsptr = HEAP32[(struct + off_ns)>>2];
- const name = UTF8ToString(HEAP32[(struct + off_name)>>2]);
- const e = nsptr ?
- document.createElementNS(UTF8ToString(nsptr), name) :
- document.createElement(name);
+ let e;
+ const type = UTF8ToString(HEAP32[(struct + off_type)>>2]);
+ const contentptr = HEAP32[(struct + off_content)>>2];
+ const content = contentptr && UTF8ToString(contentptr);
+ if (type === "text") {
+ e = document.createTextNode(content);
+ } else {
+ const nsptr = HEAP32[(struct + off_ns)>>2];
+ const name = UTF8ToString(
+ HEAP32[(struct + off_name)>>2]);
+ e = nsptr ?
+ document.createElementNS(
+ UTF8ToString(nsptr), name) :
+ document.createElement(name);
+ if (content) e.textContent = content;
+ }
const n_attrs = HEAP32[(struct + off_n_attrs)>>2];
if (n_attrs) {
@@ -81,13 +92,20 @@ function elemAppendElemv(sel, elemc, elemv, off_ns, off_name, off_content,
HEAP32[(attr_vals + i*4)>>2]));
}
- const content = HEAP32[(struct + off_content)>>2];
- if (content) e.textContent = UTF8ToString(content);
+ const n_children = HEAP32[(struct + off_n_children)>>2];
+ if (n_children)
+ targetAppendElemv(e, n_children,
+ HEAP32[(struct + off_children)>>2],
+ ...Array.prototype.slice.call(arguments, 3));
target.appendChild(e);
}
}
+function elemAppendElemv(sel, ...args) {
+ targetAppendElemv($(UTF8ToString(sel)), ...args);
+}
+
function promptHandle(command, data) {
const str_c = toCString(command);
const str_d = data && toCString(data);