summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-01-16 15:49:10 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-01-16 15:49:10 -0500
commited56c462bf4131b7e179c72bfafb4f6967bc27dc (patch)
treeee402a827eb239b280a93f70202795980b0d1dce /lib
parentc6f717a90ca7cede8af4fd7aefd7b69cf069592e (diff)
dlist example working
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js51
1 files changed, 45 insertions, 6 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 0ee19992..689792f7 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -37,26 +37,53 @@ function sb(x,y) {
return s;
}
-function myParent() {
- var pos = document;
-
+function lastParent(pos) {
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");
+}
+
+function curParent() {
+ return lastParent(parents ? parents.v : document);
+}
+
+function populate(node, html) {
+ node.innerHTML = html;
+
+ 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();
+ }
+}
+
function dyn(s) {
var x = document.createElement("span");
x.innerHTML = s.v;
- myParent().appendChild(x);
- s.h = cons(function() { x.innerHTML = s.v }, s.h);
+ curParent().appendChild(x);
+ s.h = cons(function() { populate(x, s.v) }, s.h);
}
function inp(t, s) {
var x = document.createElement(t);
x.value = s.v;
- myParent().appendChild(x);
+ curParent().appendChild(x);
s.h = cons(function() { x.value = s.v }, s.h);
x.onkeyup = function() { sv(s, x.value) };
}
@@ -70,3 +97,15 @@ function bs(b) { return (b ? "True" : "False") }
function pf() { alert("Pattern match failure") }
+var closures = [];
+
+function ca(f) {
+ var n = closures.length;
+ closures[n] = f;
+ return n;
+}
+
+function cr(n) {
+ return closures[n]();
+}
+