diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-08-06 11:54:28 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-08-06 11:54:28 -0400 |
commit | 4234e12dd51638797197ea6e6f03c05453527961 (patch) | |
tree | d59a03ba3b733dcdec316831dc6b38adb4808118 /lib/js | |
parent | 94a1373401529f500640b0c0628e7173612cdabe (diff) |
dtable example and demos both working
Diffstat (limited to 'lib/js')
-rw-r--r-- | lib/js/urweb.js | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js index dd66b55e..4d8418b6 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -228,79 +228,87 @@ function parent() { } function addNode(node) { - if (thisScript) { - thisScript.parentNode.appendChild(node); - thisScript.parentNode.removeChild(thisScript); - } else { + if (thisScript) + thisScript.parentNode.replaceChild(node, thisScript); + else lastParent().appendChild(node); - } } -function setHTML(html) { - var x = document.createElement("span"); - x.dead = false; - x.signal = null; - x.sources = null; - x.closures = null; - x.innerHTML = html; - addNode(x); - runScripts(x); -} - var thisScript = null; function runScripts(node) { - var savedScript = thisScript; - - var scripts = node.getElementsByTagName("script"), scriptsCopy = []; - var len = scripts.length; - for (var i = 0; i < len; ++i) - scriptsCopy[i] = scripts[i]; - for (var i = 0; i < len; ++i) { - thisScript = scriptsCopy[i]; - try { - eval(thisScript.textContent); - } catch (v) { - doExn(v); + if (node.getElementsByTagName) { + var savedScript = thisScript; + + var scripts = node.getElementsByTagName("script"), scriptsCopy = []; + var len = scripts.length; + for (var i = 0; i < len; ++i) + scriptsCopy[i] = scripts[i]; + for (var i = 0; i < len; ++i) { + thisScript = scriptsCopy[i]; + try { + eval(thisScript.textContent); + } catch (v) { + doExn(v); + } + if (thisScript.parentNode) + thisScripts.parentNode.removeChild(thisScript); } - } - thisScript = savedScript; + thisScript = savedScript; + } } // Dynamic tree entry points function dyn(s) { - var x = parent(); + var x = document.createElement("div"); + x.style.display = "inline"; x.dead = false; x.signal = s; x.sources = null; x.closures = null; + + var first = null; + x.recreate = function(v) { for (var ls = x.closures; ls; ls = ls.next) freeClosure(ls.data); - var doKind = function(kind) { - var arr = x.getElementsByTagName(kind); - for (var i = 0; i < arr.length; ++i) { - var span = arr[i]; - span.dead = true; - for (var ls = span.sources; ls; ls = ls.next) - ls.data.dyns = remove(span, ls.data.dyns); - for (var ls = span.closures; ls; ls = ls.next) - freeClosure(ls.data); + for (var node = first; node && node != x; ) { + if (node.getElementsByTagName) { + var arr = node.getElementsByTagName("div"); + for (var i = 0; i < arr.length; ++i) { + var span = arr[i]; + span.dead = true; + for (var ls = span.sources; ls; ls = ls.next) + ls.data.dyns = remove(span, ls.data.dyns); + for (var ls = span.closures; ls; ls = ls.next) + freeClosure(ls.data); + } } - }; - doKind("span"); - doKind("tbody"); + var old = node; + node = node.nextSibling; + old.parentNode.removeChild(old); + } var cls = {v : null}; - x.innerHTML = flatten(cls, v); + var dummy = document.createElement("table"); + dummy.innerHTML = flatten(cls, v); x.closures = cls.v; - runScripts(x); + runScripts(dummy); + + for (first = dummy.firstChild; first && first.tagName == "TBODY"; first = first.firstChild); + for (var node = first; node; ) { + var old = node; + node = node.nextSibling; + x.parentNode.insertBefore(old, x); + } }; + + addNode(x); populate(x); } @@ -310,8 +318,8 @@ function input(t, s, recreate) { x.signal = ss(s); x.sources = null; x.recreate = recreate(x); - populate(x); addNode(x); + populate(x); return x; } @@ -332,7 +340,6 @@ function sel(s, content) { sv(s, x.value); x.onchange = function() { sv(s, x.value) }; - return x; } |