# HG changeset patch # User Adam Chlipala # Date 1425416100 18000 # Node ID f89be9cd20871a6b50a493b685280d7b81160222 # Parent e3a79066380dab664965d9183c45a857c0b7823a Support 'dynClass' and 'dynStyle' for diff -r e3a79066380d -r f89be9cd2087 lib/js/urweb.js --- a/lib/js/urweb.js Mon Feb 16 14:52:56 2015 -0500 +++ b/lib/js/urweb.js Tue Mar 03 15:55:00 2015 -0500 @@ -1200,7 +1200,7 @@ 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 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) diff -r e3a79066380d -r f89be9cd2087 src/monoize.sml --- a/src/monoize.sml Mon Feb 16 14:52:56 2015 -0500 +++ b/src/monoize.sml Tue Mar 03 15:55:00 2015 -0500 @@ -3267,6 +3267,11 @@ else (NONE, NONE, attrs) + val (class, fm) = monoExp (env, st, fm) class + val (dynClass, fm) = monoExp (env, st, fm) dynClass + val (style, fm) = monoExp (env, st, fm) style + val (dynStyle, fm) = monoExp (env, st, fm) dynStyle + (* Special case for