on master help sign in
Fix sizing bug in runtime system.
commitc9a6398cd83e79692ec2293746d0184a48b0ee72 authorevancz <info@elm-lang.org> dateTue 12 Jun 2012, 05:44 (14 years ago) parent03c1dd8
3 files changed+49−16
core-js/Element.js+36−13 core-js/Everything.js+7−1 core-js/runtime/Dispatcher.js+6−2
core-js/Element.js+36−13
@@ -42,28 +42,46 @@ var Element = function() {
4242 addTo(div, e);
4343 return div;
4444 };
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+
4555 var makeText = function(w) { return function(pos) { return function(txt) {
4656 var e = newElement('div');
57+ e.isElmLeaf = true;
4758 e.isElmText = true;
4859 e.innerHTML = txt;
4960 e.style.textAlign = pos;
5061 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";
6362 return e;
6463 };
6564 };
6665 };
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+
6785 var link = function (href) { return function (e) {
6886 var a = newElement('a');
6987 a.href = Text.fromString(href);
@@ -77,6 +95,7 @@ var Element = function() {
7795 return makeText(0)("left")(Data.String.toText(str)); };
7896 var justifiedText = makeText(0)('justify');
7997 var centeredText = makeText(0)('center');
98+ var rightedText = makeText(0)('right');
8099 var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
81100
82101 var image = function(src) {
@@ -275,6 +294,7 @@ var Element = function() {
275294 collage : collage,
276295 flow : flow,
277296 layers : flow(2),
297+ rectangle : rectangle,
278298
279299 beside : beside,
280300 above : above,
@@ -292,6 +312,7 @@ var Element = function() {
292312 plainText : plainText,
293313 justifiedText : justifiedText,
294314 centeredText : centeredText,
315+ rightedText : rightedText,
295316
296317 // directions
297318 up : 0,
@@ -299,7 +320,9 @@ var Element = function() {
299320 inward : 2,
300321 down : 3,
301322 right : 4,
302− outward : 5
323+ outward : 5,
324+
325+ correctTextSize : correctTextSize
303326 };
304327}();
305328
core-js/Everything.js+7−1
@@ -94,4 +94,10 @@ var includeGlobal = this;
9494 include (Color);
9595 include (Shape);
9696 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() {
7474 var kids = e.childNodes;
7575 var len = kids.length;
7676 if (e.hasOwnProperty('isElmLeaf')) {
77+ if (e.hasOwnProperty('isElmText')) { Element.correctTextSize(e); }
7778 var w = e.style.width === "" ?
7879 0 : e.style.width.slice(0,-2) - 0;
7980 var h = e.style.height === "" ?
@@ -108,8 +109,11 @@ var Dispatcher = function() {
108109 };
109110
110111 var initialize = function() {
111− try { program = main(); } catch (e) {
112− document.body.innerHTML = monospace("Runtime Error:<br>JavaScript " + e);
112+ var prog = ElmCode.hasOwnProperty("main") ? ElmCode.main : main;
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>")
116+ document.body.innerHTML = Text.monospace(msg);
113117 throw e;
114118 }
115119 if (!program.hasOwnProperty('recv')) {