diff lib/js/urweb.js @ 1751:acadf9d1214a

'dynStyle' pseudo-attribute
author Adam Chlipala <adam@chlipala.net>
date Sun, 06 May 2012 15:15:46 -0400
parents 6f2f74cc4ead
children e9587120831a
line wrap: on
line diff
--- a/lib/js/urweb.js	Sun May 06 14:01:29 2012 -0400
+++ b/lib/js/urweb.js	Sun May 06 15:15:46 2012 -0400
@@ -944,7 +944,7 @@
     return x;
 }
 
-function dynClass(html, s) {
+function dynClass(html, s_class, s_style) {
     var htmlCls = {v : null};
     html = flatten(htmlCls, html);
     htmlCls = htmlCls.v;
@@ -956,23 +956,45 @@
     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);
+    if (s_class) {
+        var x = document.createElement("script");
+        x.dead = false;
+        x.signal = s_class;
+        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);
-    };
+            var cls = {v : null};
+            html.className = flatten(cls, v);
+	    x.closures = concat(cls.v, htmlCls);
+        }
 
-    addNode(x);
-    populate(x);
+        addNode(x);
+        populate(x);
+    }
+
+    if (s_style) {
+        var x = document.createElement("script");
+        x.dead = false;
+        x.signal = s_style;
+        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.style.cssText = flatten(cls, v);
+	    x.closures = concat(cls.v, htmlCls);
+        }
+
+        addNode(x);
+        populate(x);
+    }
 }
 
 function addOnChange(x, f) {