summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2015-03-03 15:55:00 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2015-03-03 15:55:00 -0500
commit4906733e1c12fd167a4236c63201a8f4e6daad63 (patch)
treee556192545ac6b5bcf12babc0de45bf8124ff011 /lib
parentedc47c5a3cc1e717c45229ca674d5337771fd5e1 (diff)
Support 'dynClass' and 'dynStyle' for <body>
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js52
1 files changed, 51 insertions, 1 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 3bf21dd2..bd5109c3 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1200,7 +1200,7 @@ function dynClass(pnode, html, s_class, s_style) {
x.dead = false;
x.signal = s_class;
x.sources = null;
- x.closures = htmlCls;
+ x.closures = null;
x.recreate = function(v) {
for (var ls = x.closures; ls != htmlCls; ls = ls.next)
@@ -1237,6 +1237,56 @@ function dynClass(pnode, html, s_class, s_style) {
}
}
+function bodyDynClass(s_class, s_style) {
+ if (suspendScripts)
+ return;
+
+ var htmlCls = null;
+
+ 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};
+ document.body.className = flatten(cls, v);
+ console.log("className to + " + document.body.className);
+ x.closures = concat(cls.v, htmlCls);
+ }
+
+ document.body.appendChild(x);
+ populate(x);
+ }
+
+ if (s_style) {
+ var htmlCls2 = s_class ? null : htmlCls;
+ var y = document.createElement("script");
+ y.dead = false;
+ y.signal = s_style;
+ y.sources = null;
+ y.closures = htmlCls2;
+
+ y.recreate = function(v) {
+ for (var ls = y.closures; ls != htmlCls2; ls = ls.next)
+ freeClosure(ls.data);
+
+ var cls = {v : null};
+ document.body.style.cssText = flatten(cls, v);
+ console.log("style to + " + document.body.style.cssText);
+ y.closures = concat(cls.v, htmlCls2);
+ }
+
+ document.body.appendChild(y);
+ populate(y);
+ }
+}
+
function addOnChange(x, f) {
var old = x.onchange;
if (old == null)