summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-12-27 16:20:48 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2011-12-27 16:20:48 -0500
commitcbc7945fff250fe24dc91bcaa3fec2d635dc052a (patch)
treeb79292fd3c487498c7837ad6008636a1ed5163cf /lib
parenta8b2771f6e2526855ae3387b876d7f861b53c817 (diff)
'dynClass' pseudo-attribute
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js34
-rw-r--r--lib/ur/basis.urs1
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index a3976fef..ba73e744 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -47,7 +47,7 @@ function cons(v, ls) {
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 @@ function flattenLocal(s) {
}
-
// Dynamic tree management
function populate(node) {
@@ -899,6 +898,37 @@ function tbx(s) {
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)
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index 17e969ef..08585546 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -645,6 +645,7 @@ val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type}
[useOuter ~ useInner] =>
[bindOuter ~ bindInner] =>
option css_class
+ -> option (signal css_class)
-> $attrsGiven
-> tag (attrsGiven ++ attrsAbsent)
ctxOuter ctxInner useOuter bindOuter