on master help sign in
Fix sizing bug in runtime system.
c9a6398evancz
core-js/Element.js+36−13
@@ -42,28 +42,46 @@ var Element = function() {
42 addTo(div, e);
42 addTo(div, e);
43 return div;
43 return div;
44 };
44 };
45+
46+ var rectangle = function(w) { return function(h) {
47+ var e = newElement('div');
48+ e.isElmLeaf = true;
49+ e.style.width = w + "px";
50+ e.style.height = h + "px";
51+ return e;
52+ };
53+ };
54+
45 var makeText = function(w) { return function(pos) { return function(txt) {
55 var makeText = function(w) { return function(pos) { return function(txt) {
46 var e = newElement('div');
56 var e = newElement('div');
57+ e.isElmLeaf = true;
47 e.isElmText = true;
58 e.isElmText = true;
48 e.innerHTML = txt;
59 e.innerHTML = txt;
49 e.style.textAlign = pos;
60 e.style.textAlign = pos;
50 if (w > 0) e.style.width = w + "px";
61 if (w > 0) e.style.width = w + "px";
51− e.isElmLeaf = true;
52− e.style.visibility = "hidden";
53− e.style.styleFloat = "left";
54− e.style.cssFloat = "left";
55− document.body.appendChild(e);
56− var cStyle = window.getComputedStyle(e);
57− if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
58− e.style.height = cStyle.getPropertyValue("height");
59− document.body.removeChild(e);
60− e.style.visibility = "visible"
61− e.style.styleFloat = "none";
62− e.style.cssFloat = "none";
63 return e;
62 return e;
64 };
63 };
65 };
64 };
66 };
65 };
66+ var correctTextSize = function(e) {
67+ var w = e.style.width ? e.style.width.slice(0,-2) : 0;
68+
69+ var t = newElement('div');
70+ t.innerHTML = "&nbsp;" + e.innerHTML;
71+ t.style.textAlign = e.style.textAlign;
72+ if (w > 0) { t.style.width = w + "px"; }
73+
74+ t.style.visibility = "hidden";
75+ t.style.styleFloat = "left";
76+ t.style.cssFloat = "left";
77+
78+ document.body.appendChild(t);
79+ var cStyle = window.getComputedStyle(t);
80+ if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
81+ e.style.height = cStyle.getPropertyValue("height");
82+ document.body.removeChild(t);
83+ };
84+
67 var link = function (href) { return function (e) {
85 var link = function (href) { return function (e) {
68 var a = newElement('a');
86 var a = newElement('a');
69 a.href = Text.fromString(href);
87 a.href = Text.fromString(href);
@@ -77,6 +95,7 @@ var Element = function() {
77 return makeText(0)("left")(Data.String.toText(str)); };
95 return makeText(0)("left")(Data.String.toText(str)); };
78 var justifiedText = makeText(0)('justify');
96 var justifiedText = makeText(0)('justify');
79 var centeredText = makeText(0)('center');
97 var centeredText = makeText(0)('center');
98+ var rightedText = makeText(0)('right');
80 var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
99 var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
81
100
82 var image = function(src) {
101 var image = function(src) {
@@ -275,6 +294,7 @@ var Element = function() {
275 collage : collage,
294 collage : collage,
276 flow : flow,
295 flow : flow,
277 layers : flow(2),
296 layers : flow(2),
297+ rectangle : rectangle,
278
298
279 beside : beside,
299 beside : beside,
280 above : above,
300 above : above,
@@ -292,6 +312,7 @@ var Element = function() {
292 plainText : plainText,
312 plainText : plainText,
293 justifiedText : justifiedText,
313 justifiedText : justifiedText,
294 centeredText : centeredText,
314 centeredText : centeredText,
315+ rightedText : rightedText,
295
316
296 // directions
317 // directions
297 up : 0,
318 up : 0,
@@ -299,7 +320,9 @@ var Element = function() {
299 inward : 2,
320 inward : 2,
300 down : 3,
321 down : 3,
301 right : 4,
322 right : 4,
302− outward : 5
323+ outward : 5,
324+
325+ correctTextSize : correctTextSize
303 };
326 };
304}();
327}();
305
328
core-js/Everything.js+7−1
@@ -94,4 +94,10 @@ var includeGlobal = this;
94 include (Color);
94 include (Color);
95 include (Shape);
95 include (Shape);
96 include (Line);
96 include (Line);
97+
97−}());
98+}());
99+
100+var ElmCode = {};
101+ElmCode.Data = Data;
102+ElmCode.Signal = Signal;
103+ElmCode.Data.List = List;
core-js/runtime/Dispatcher.js+6−2
@@ -74,6 +74,7 @@ var Dispatcher = function() {
74 var kids = e.childNodes;
74 var kids = e.childNodes;
75 var len = kids.length;
75 var len = kids.length;
76 if (e.hasOwnProperty('isElmLeaf')) {
76 if (e.hasOwnProperty('isElmLeaf')) {
77+ if (e.hasOwnProperty('isElmText')) { Element.correctTextSize(e); }
77 var w = e.style.width === "" ?
78 var w = e.style.width === "" ?
78 0 : e.style.width.slice(0,-2) - 0;
79 0 : e.style.width.slice(0,-2) - 0;
79 var h = e.style.height === "" ?
80 var h = e.style.height === "" ?
@@ -108,8 +109,11 @@ var Dispatcher = function() {
108 };
109 };
109
110
110 var initialize = function() {
111 var initialize = function() {
112+ var prog = ElmCode.hasOwnProperty("main") ? ElmCode.main : main;
111− try { program = main(); } catch (e) {
113+ try { program = prog(); } catch (e) {
114+ var msg = ("<br><h2>Your browser may not be supported. Are you using a modern browser?</h2>" +
115+ "<br><span style=\"grey\">Runtime Error:<br>" + e + "</span>")
112− document.body.innerHTML = monospace("Runtime Error:<br>JavaScript " + e);
116+ document.body.innerHTML = Text.monospace(msg);
113 throw e;
117 throw e;
114 }
118 }
115 if (!program.hasOwnProperty('recv')) {
119 if (!program.hasOwnProperty('recv')) {