diff options
author | 2009-01-16 15:49:10 -0500 | |
---|---|---|
committer | 2009-01-16 15:49:10 -0500 | |
commit | 45ac3423d55ad88509374176ca15eca34afd0f1e (patch) | |
tree | ee402a827eb239b280a93f70202795980b0d1dce /lib/js/urweb.js | |
parent | c962db0783caec9d00a3fe3b01733f1660305834 (diff) |
dlist example working
Diffstat (limited to 'lib/js/urweb.js')
-rw-r--r-- | lib/js/urweb.js | 51 |
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](); +} + |