diff options
Diffstat (limited to 'lib/js')
-rw-r--r-- | lib/js/urweb.js | 52 |
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) |