comparison lib/js/urweb.js @ 1643:b0720700c36e

'dynClass' pseudo-attribute
author Adam Chlipala <adam@chlipala.net>
date Tue, 27 Dec 2011 16:20:48 -0500
parents 4682b312e9d5
children 1bfd793e7eb8
comparison
equal deleted inserted replaced
1642:c3627f317bfd 1643:b0720700c36e
45 return { next : ls, data : v }; 45 return { next : ls, data : v };
46 } 46 }
47 function rev(ls) { 47 function rev(ls) {
48 var acc = null; 48 var acc = null;
49 for (; ls; ls = ls.next) 49 for (; ls; ls = ls.next)
50 acc = cons(ls.data, acc); 50 acc = cons(ls.data, acc);
51 return acc; 51 return acc;
52 } 52 }
53 function concat(ls1, ls2) { 53 function concat(ls1, ls2) {
54 var acc = ls2; 54 var acc = ls2;
55 ls1 = rev(ls1); 55 ls1 = rev(ls1);
560 freeClosure(cl.data); 560 freeClosure(cl.data);
561 return r; 561 return r;
562 } 562 }
563 563
564 564
565
566 // Dynamic tree management 565 // Dynamic tree management
567 566
568 function populate(node) { 567 function populate(node) {
569 var s = node.signal; 568 var s = node.signal;
570 var oldSources = node.sources; 569 var oldSources = node.sources;
895 function(x) { return function(v) { if (x.innerHTML != v) x.innerHTML = v; }; }); 894 function(x) { return function(v) { if (x.innerHTML != v) x.innerHTML = v; }; });
896 x.innerHTML = s.data; 895 x.innerHTML = s.data;
897 x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, x.value) }; 896 x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, x.value) };
898 897
899 return x; 898 return x;
899 }
900
901 function dynClass(html, s) {
902 var htmlCls = {v : null};
903 html = flatten(htmlCls, html);
904 htmlCls = htmlCls.v;
905
906 var dummy = document.createElement("body");
907 dummy.innerHTML = html;
908 runScripts(dummy);
909 var html = dummy.firstChild;
910 dummy.removeChild(html);
911 addNode(html);
912
913 var x = document.createElement("script");
914 x.dead = false;
915 x.signal = s;
916 x.sources = null;
917 x.closures = htmlCls;
918
919 x.recreate = function(v) {
920 for (var ls = x.closures; ls != htmlCls; ls = ls.next)
921 freeClosure(ls.data);
922
923 var cls = {v : null};
924 html.className = flatten(cls, v);
925 x.closures = concat(cls.v, htmlCls);
926 };
927
928 addNode(x);
929 populate(x);
900 } 930 }
901 931
902 function addOnChange(x, f) { 932 function addOnChange(x, f) {
903 var old = x.onchange; 933 var old = x.onchange;
904 if (old == null) 934 if (old == null)