aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/js
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-03-14 10:10:56 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-03-14 10:10:56 -0400
commite90f7afc607a0af326c87ebb184b7eacfee8b92b (patch)
tree30712b447483786217c20367a7f29491305fe2db /lib/js
parent3b4137c893c21d68a1dbecdcb3acd865dd32057d (diff)
New JavaScript FFI function: setInnerHTML
Diffstat (limited to 'lib/js')
-rw-r--r--lib/js/urweb.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index e6c2124f..5a18e17c 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -836,6 +836,38 @@ function dyn(pnode, s) {
populate(x);
}
+function setInnerHTML(node, html) {
+ var x;
+
+ if (node.previousSibling && node.previousSibling.closures != undefined) {
+ x = node.previousSibling;
+
+ for (var ls = x.closures; ls; ls = ls.next)
+ freeClosure(ls.data);
+
+ if (node.getElementsByTagName) {
+ var arr = node.getElementsByTagName("script");
+ for (var i = 0; i < arr.length; ++i)
+ killScript(arr[i]);
+ }
+ } else {
+ x = document.createElement("script");
+ x.dead = false;
+ x.sources = null;
+
+ if (node.parentNode)
+ node.parentNode.insertBefore(x, node);
+ else
+ whine("setInnerHTML: node is not already in the DOM tree");
+ }
+
+ var cls = {v : null};
+ var html = flatten(cls, html);
+ x.closures = cls.v;
+ node.innerHTML = html;
+ runScripts(node);
+}
+
function input(x, s, recreate, type, name) {
if (name) x.name = name;
if (type) x.type = type;