on master help sign in
fix spacing again
3c7f45fEvan Czaplicki
runtime/Render/Element.js+73−73
@@ -12,15 +12,15 @@ function setProps(props, e) {
12 e.style.height = (props.height|0) + 'px';
12 e.style.height = (props.height|0) + 'px';
13 if (props.opacity !== 1) { e.style.opacity = props.opacity; }
13 if (props.opacity !== 1) { e.style.opacity = props.opacity; }
14 if (props.color.ctor === 'Just') {
14 if (props.color.ctor === 'Just') {
15− e.style.backgroundColor = extract(props.color._0);
15+ e.style.backgroundColor = extract(props.color._0);
16 }
16 }
17 if (props.tag !== '') { e.id = props.tag; }
17 if (props.tag !== '') { e.id = props.tag; }
18 if (props.href !== '') {
18 if (props.href !== '') {
19− var a = newElement('a');
19+ var a = newElement('a');
20− a.href = props.href;
20+ a.href = props.href;
21 a.style.display = 'block';
21 a.style.display = 'block';
22− a.appendChild(e);
22+ a.appendChild(e);
23− return a;
23+ return a;
24 }
24 }
25 if (props.hover.ctor !== '_Tuple0') {
25 if (props.hover.ctor !== '_Tuple0') {
26 var overCount = 0;
26 var overCount = 0;
@@ -77,11 +77,11 @@ function croppedImage(elem, w, h, src) {
77
77
78 var img = newElement('img');
78 var img = newElement('img');
79 img.onload = function() {
79 img.onload = function() {
80− var sw = w / elem._1, sh = h / elem._2;
80+ var sw = w / elem._1, sh = h / elem._2;
81− img.style.width = ((this.width * sw)|0) + 'px';
81+ img.style.width = ((this.width * sw)|0) + 'px';
82− img.style.height = ((this.height * sh)|0) + 'px';
82+ img.style.height = ((this.height * sh)|0) + 'px';
83− img.style.marginLeft = ((- pos._0 * sw)|0) + 'px';
83+ img.style.marginLeft = ((- pos._0 * sw)|0) + 'px';
84− img.style.marginTop = ((- pos._1 * sh)|0) + 'px';
84+ img.style.marginTop = ((- pos._1 * sh)|0) + 'px';
85 };
85 };
86 img.src = src;
86 img.src = src;
87 img.name = src;
87 img.name = src;
@@ -95,7 +95,7 @@ function goRight(e) { e.style.styleFloat = e.style.cssFloat = "left"; return e;
95function flowWith(f, array) {
95function flowWith(f, array) {
96 var container = newElement('div');
96 var container = newElement('div');
97 for (var i = array.length; i--; ) {
97 for (var i = array.length; i--; ) {
98− container.appendChild(f(render(array[i])));
98+ container.appendChild(f(render(array[i])));
99 }
99 }
100 return container;
100 return container;
101}
101}
@@ -170,8 +170,8 @@ function update(node, curr, next) {
170 if (node.tagName === 'A') { node = node.firstChild; }
170 if (node.tagName === 'A') { node = node.firstChild; }
171 if (curr.props.id === next.props.id) return updateProps(node, curr, next);
171 if (curr.props.id === next.props.id) return updateProps(node, curr, next);
172 if (curr.element.ctor !== next.element.ctor) {
172 if (curr.element.ctor !== next.element.ctor) {
173− node.parentNode.replaceChild(render(next),node);
173+ node.parentNode.replaceChild(render(next),node);
174− return true;
174+ return true;
175 }
175 }
176 var nextE = next.element, currE = curr.element;
176 var nextE = next.element, currE = curr.element;
177 switch(nextE.ctor) {
177 switch(nextE.ctor) {
@@ -180,61 +180,61 @@ function update(node, curr, next) {
180 if (nextE._0 !== currE._0) node.innerHTML = nextE._0;
180 if (nextE._0 !== currE._0) node.innerHTML = nextE._0;
181 break;
181 break;
182 case "Image":
182 case "Image":
183− if (nextE._0.ctor === 'Plain') {
183+ if (nextE._0.ctor === 'Plain') {
184− if (nextE._3 !== currE._3) node.src = nextE._3;
184+ if (nextE._3 !== currE._3) node.src = nextE._3;
185− } else if (!eq(nextE,currE) ||
185+ } else if (!eq(nextE,currE) ||
186− next.props.width !== curr.props.width ||
186+ next.props.width !== curr.props.width ||
187− next.props.height !== curr.props.height) {
187+ next.props.height !== curr.props.height) {
188− node.parentNode.replaceChild(render(next),node);
188+ node.parentNode.replaceChild(render(next),node);
189− return true;
189+ return true;
190− }
190+ }
191− break;
191+ break;
192 case "Flow":
192 case "Flow":
193 var arr = fromList(nextE._1);
193 var arr = fromList(nextE._1);
194 for (var i = arr.length; i--; ) { arr[i] = arr[i].element.ctor; }
194 for (var i = arr.length; i--; ) { arr[i] = arr[i].element.ctor; }
195− if (nextE._0.ctor !== currE._0.ctor) {
195+ if (nextE._0.ctor !== currE._0.ctor) {
196− node.parentNode.replaceChild(render(next),node);
196+ node.parentNode.replaceChild(render(next),node);
197− return true;
197+ return true;
198− }
198+ }
199− var nexts = fromList(nextE._1);
199+ var nexts = fromList(nextE._1);
200− var kids = node.childNodes;
200+ var kids = node.childNodes;
201− if (nexts.length !== kids.length) {
201+ if (nexts.length !== kids.length) {
202− node.parentNode.replaceChild(render(next),node);
202+ node.parentNode.replaceChild(render(next),node);
203− return true;
203+ return true;
204− }
204+ }
205− var currs = fromList(currE._1);
205+ var currs = fromList(currE._1);
206− var goDir = function(x) { return x; };
206+ var goDir = function(x) { return x; };
207− switch(nextE._0.ctor) {
207+ switch(nextE._0.ctor) {
208− case "DDown": case "DUp": goDir = goDown; break;
208+ case "DDown": case "DUp": goDir = goDown; break;
209− case "DRight": case "DLeft": goDir = goRight; break;
209+ case "DRight": case "DLeft": goDir = goRight; break;
210− case "DOut": case "DIn": goDir = goIn; break;
210+ case "DOut": case "DIn": goDir = goIn; break;
211− }
211+ }
212− for (var i = kids.length; i-- ;) {
212+ for (var i = kids.length; i-- ;) {
213− update(kids[i],currs[i],nexts[i]);
213+ update(kids[i],currs[i],nexts[i]);
214− goDir(kids[i]);
214+ goDir(kids[i]);
215− }
215+ }
216− break;
216+ break;
217 case "Container":
217 case "Container":
218− var inner = node.firstChild;
218+ var inner = node.firstChild;
219− if (!update(inner, currE._1, nextE._1)) {
219+ if (!update(inner, currE._1, nextE._1)) {
220− if (nextE._0.horizontal.ctor !== currE._0.horizontal.ctor) {
220+ if (nextE._0.horizontal.ctor !== currE._0.horizontal.ctor) {
221− inner.style.left = inner.style.right = 'none';
221+ inner.style.left = inner.style.right = 'none';
222− removeTransform(inner.style);
222+ removeTransform(inner.style);
223− }
223+ }
224− if (nextE._0.vertical.ctor !== currE._0.vertical.ctor) {
224+ if (nextE._0.vertical.ctor !== currE._0.vertical.ctor) {
225− inner.style.top = inner.style.bottom = 'none';
225+ inner.style.top = inner.style.bottom = 'none';
226− removeTransform(inner.style);
226+ removeTransform(inner.style);
227− }
227+ }
228− }
228+ }
229− setPos(nextE._0, nextE._1.props.width, nextE._1.props.height, inner);
229+ setPos(nextE._0, nextE._1.props.width, nextE._1.props.height, inner);
230− break;
230+ break;
231 case "Custom":
231 case "Custom":
232− if (currE.type === nextE.type) {
232+ if (currE.type === nextE.type) {
233− var done = nextE.update(node, currE.model, nextE.model);
233+ var done = nextE.update(node, currE.model, nextE.model);
234− if (done) return;
234+ if (done) return;
235− } else {
235+ } else {
236− return node.parentNode.replaceChild(render(next), node);
236+ return node.parentNode.replaceChild(render(next), node);
237− }
237+ }
238 }
238 }
239 updateProps(node, curr, next);
239 updateProps(node, curr, next);
240}
240}
@@ -244,23 +244,23 @@ function updateProps(node, curr, next) {
244 if (props.width !== currP.width) e.style.width = (props.width |0) + 'px';
244 if (props.width !== currP.width) e.style.width = (props.width |0) + 'px';
245 if (props.height !== currP.height) e.style.height = (props.height|0) + 'px';
245 if (props.height !== currP.height) e.style.height = (props.height|0) + 'px';
246 if (props.opacity !== 1 && props.opacity !== currP.opacity) {
246 if (props.opacity !== 1 && props.opacity !== currP.opacity) {
247− e.style.opacity = props.opacity;
247+ e.style.opacity = props.opacity;
248 }
248 }
249 var nextColor = (props.color.ctor === 'Just' ?
249 var nextColor = (props.color.ctor === 'Just' ?
250− extract(props.color._0) : 'transparent');
250+ extract(props.color._0) : 'transparent');
251 if (e.style.backgroundColor !== nextColor) {
251 if (e.style.backgroundColor !== nextColor) {
252 e.style.backgroundColor = nextColor;
252 e.style.backgroundColor = nextColor;
253 }
253 }
254 if (props.tag !== currP.tag) { e.id = props.tag; }
254 if (props.tag !== currP.tag) { e.id = props.tag; }
255 if (props.href !== currP.href) {
255 if (props.href !== currP.href) {
256− if (currP.href === '') {
256+ if (currP.href === '') {
257− var a = newElement('a');
257+ var a = newElement('a');
258− a.href = props.href;
258+ a.href = props.href;
259− a.appendChild(e);
259+ a.appendChild(e);
260− e.parentNode.replaceChild(a,e);
260+ e.parentNode.replaceChild(a,e);
261− } else {
261+ } else {
262− node.parentNode.href = props.href;
262+ node.parentNode.href = props.href;
263− }
263+ }
264 }
264 }
265}
265}
266
266