Mercurial > urweb
comparison lib/js/urweb.js @ 2012:2b2d07946e65
Fix dynClass for non-<body> contexts
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 04 May 2014 12:33:44 -0400 |
parents | 93ff76058825 |
children | 534577e429e1 |
comparison
equal
deleted
inserted
replaced
2011:cfd604842006 | 2012:2b2d07946e65 |
---|---|
1111 x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, x.value) }; | 1111 x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, x.value) }; |
1112 | 1112 |
1113 return x; | 1113 return x; |
1114 } | 1114 } |
1115 | 1115 |
1116 function dynClass(html, s_class, s_style) { | 1116 function dynClass(pnode, html, s_class, s_style) { |
1117 if (suspendScripts) | 1117 if (suspendScripts) |
1118 return; | 1118 return; |
1119 | 1119 |
1120 var htmlCls = {v : null}; | 1120 var htmlCls = {v : null}; |
1121 html = flatten(htmlCls, html); | 1121 html = flatten(htmlCls, html); |
1122 htmlCls = htmlCls.v; | 1122 htmlCls = htmlCls.v; |
1123 | 1123 |
1124 var dummy = document.createElement("body"); | 1124 var dummy = document.createElement(pnode); |
1125 suspendScripts = true; | 1125 suspendScripts = true; |
1126 dummy.innerHTML = html; | 1126 dummy.innerHTML = html; |
1127 suspendScripts = false; | 1127 suspendScripts = false; |
1128 var html = dummy.firstChild; | 1128 var html = dummy.firstChild; |
1129 dummy.removeChild(html); | 1129 dummy.removeChild(html); |
1150 populate(x); | 1150 populate(x); |
1151 } | 1151 } |
1152 | 1152 |
1153 if (s_style) { | 1153 if (s_style) { |
1154 var htmlCls2 = s_class ? null : htmlCls; | 1154 var htmlCls2 = s_class ? null : htmlCls; |
1155 var x = document.createElement("script"); | 1155 var y = document.createElement("script"); |
1156 x.dead = false; | 1156 y.dead = false; |
1157 x.signal = s_style; | 1157 y.signal = s_style; |
1158 x.sources = null; | 1158 y.sources = null; |
1159 x.closures = htmlCls2; | 1159 y.closures = htmlCls2; |
1160 | 1160 |
1161 x.recreate = function(v) { | 1161 y.recreate = function(v) { |
1162 for (var ls = x.closures; ls != htmlCls2; ls = ls.next) | 1162 for (var ls = y.closures; ls != htmlCls2; ls = ls.next) |
1163 freeClosure(ls.data); | 1163 freeClosure(ls.data); |
1164 | 1164 |
1165 var cls = {v : null}; | 1165 var cls = {v : null}; |
1166 html.style.cssText = flatten(cls, v); | 1166 html.style.cssText = flatten(cls, v); |
1167 x.closures = concat(cls.v, htmlCls2); | 1167 y.closures = concat(cls.v, htmlCls2); |
1168 } | 1168 } |
1169 | 1169 |
1170 html.appendChild(x); | 1170 html.appendChild(y); |
1171 populate(x); | 1171 populate(y); |
1172 } | 1172 } |
1173 } | 1173 } |
1174 | 1174 |
1175 function addOnChange(x, f) { | 1175 function addOnChange(x, f) { |
1176 var old = x.onchange; | 1176 var old = x.onchange; |