diff lib/js/urweb.js @ 1643:b0720700c36e

'dynClass' pseudo-attribute
author Adam Chlipala <adam@chlipala.net>
date Tue, 27 Dec 2011 16:20:48 -0500
parents 4682b312e9d5
children 1bfd793e7eb8
line wrap: on
line diff
--- a/lib/js/urweb.js	Tue Dec 20 21:06:25 2011 -0500
+++ b/lib/js/urweb.js	Tue Dec 27 16:20:48 2011 -0500
@@ -47,7 +47,7 @@
 function rev(ls) {
     var acc = null;
     for (; ls; ls = ls.next)
-        acc = cons(ls.data, acc);
+       acc = cons(ls.data, acc);
     return acc;
 }
 function concat(ls1, ls2) {
@@ -562,7 +562,6 @@
 }
 
 
-
 // Dynamic tree management
 
 function populate(node) {
@@ -899,6 +898,37 @@
     return x;
 }
 
+function dynClass(html, s) {
+    var htmlCls = {v : null};
+    html = flatten(htmlCls, html);
+    htmlCls = htmlCls.v;
+
+    var dummy = document.createElement("body");
+    dummy.innerHTML = html;
+    runScripts(dummy);
+    var html = dummy.firstChild;
+    dummy.removeChild(html);
+    addNode(html);
+
+    var x = document.createElement("script");
+    x.dead = false;
+    x.signal = s;
+    x.sources = null;
+    x.closures = htmlCls;
+    
+    x.recreate = function(v) {
+        for (var ls = x.closures; ls != htmlCls; ls = ls.next)
+            freeClosure(ls.data);
+
+        var cls = {v : null};
+        html.className = flatten(cls, v);
+	x.closures = concat(cls.v, htmlCls);
+    };
+
+    addNode(x);
+    populate(x);
+}
+
 function addOnChange(x, f) {
     var old = x.onchange;
     if (old == null)