summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/js/urweb.js47
-rw-r--r--tests/dlist.ur2
2 files changed, 25 insertions, 24 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 689792f7..7bb6849e 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -37,53 +37,54 @@ function sb(x,y) {
return s;
}
-function lastParent(pos) {
+function lastParent() {
+ var pos = document;
+
while (pos.lastChild && pos.lastChild.nodeType == 1)
pos = pos.lastChild;
return pos.parentNode;
}
-var parents = null;
-
-function pushParent(node) {
- parents = cons(node, parents);
-}
-
-function popParent() {
- if (parents)
- parents = parents.n;
- else
- alert("popParent: stack underflow");
-}
+var thisScript = null;
-function curParent() {
- return lastParent(parents ? parents.v : document);
+function addNode(node) {
+ if (thisScript) {
+ thisScript.parentNode.appendChild(node);
+ thisScript.parentNode.removeChild(thisScript);
+ } else
+ lastParent().appendChild(node);
}
-function populate(node, html) {
- node.innerHTML = html;
+function runScripts(node) {
+ var savedScript = thisScript;
var scripts = node.getElementsByTagName("script");
var len = scripts.length;
for (var i = 0; i < len; ++i) {
- pushParent(scripts[i].parentNode);
- eval(scripts[i].textContent);
- popParent();
+ thisScript = scripts[i];
+ eval(thisScript.textContent);
}
+
+ thisScript = savedScript;
+}
+
+function populate(node, html) {
+ node.innerHTML = html;
+ runScripts(node);
}
function dyn(s) {
var x = document.createElement("span");
- x.innerHTML = s.v;
- curParent().appendChild(x);
+ populate(x, s.v);
+ addNode(x);
s.h = cons(function() { populate(x, s.v) }, s.h);
}
function inp(t, s) {
var x = document.createElement(t);
x.value = s.v;
- curParent().appendChild(x);
+ addNode(x);
s.h = cons(function() { x.value = s.v }, s.h);
x.onkeyup = function() { sv(s, x.value) };
}
diff --git a/tests/dlist.ur b/tests/dlist.ur
index dbf8c3c5..0733a0db 100644
--- a/tests/dlist.ur
+++ b/tests/dlist.ur
@@ -3,7 +3,7 @@ datatype dlist = Nil | Cons of string * source dlist
fun delist dl =
case dl of
Nil => <xml>[]</xml>
- | Cons (x, s) => <xml>{[x]} :: {delistSource s}</xml>
+ | Cons (x, s) => <xml>{[x]} :: ({delistSource s})</xml>
and delistSource s = <xml><dyn signal={dl <- signal s; return (delist dl)}/></xml>