on master help sign in
Add height check and get rid of utils which was in the wrong place (i think)
commit609dc36596518cf479527cb8bbaa298e02dbbc68 authorevancz <info@elm-lang.org> dateTue 12 Mar 2013, 21:25 (14 years ago) parent55137ac
2 files changed+17−41
libraries/Native/Graphics/Text.js+17−1 runtime/Render/Utils.js−40
libraries/Native/Graphics/Text.js+17−1
@@ -82,11 +82,27 @@ Elm.Native.Graphics.Text = function(elm) {
8282 return "<a href='" + toText(href) + "'>" + text + "</a>";
8383 }
8484
85+ function htmlHeight(txt, width) {
86+ var t = document.createElement('div');
87+ t.innerHTML = html;
88+ t.style.width = w + "px";
89+ t.style.visibility = "hidden";
90+ t.style.styleFloat = "left";
91+ t.style.cssFloat = "left";
92+
93+ document.body.appendChild(t);
94+ var h = t.clientHeight
95+ document.body.removeChild(t);
96+
97+ return h;
98+ }
99+
85100 function position(pos) { return function(text) {
86101 var e = {ctor:'RawHtml',
87102 _0: '<div style="padding:0;margin:0;text-align:'+pos+'">'+text+'</div>'
88103 };
89− return A3(Element.newElement, 0, 0, e);
104+ var w = elm.node.clientWidth;
105+ return A3(Element.newElement, w, htmlHeight(text, w), e);
90106 }
91107 }
92108
runtime/Render/Utils.jsdeleted−40
@@ -1,40 +0,0 @@
1−
2−ElmRuntime.Render.Utils = function() {
3− 'use strict';
4−
5− function htmlSize(txt, width) {
6− var t = document.createElement('div');
7− t.innerHTML = html;
8− t.style.width = w + "px";
9−
10− t.style.visibility = "hidden";
11− t.style.styleFloat = "left";
12− t.style.cssFloat = "left";
13−
14− document.body.appendChild(t);
15− var cStyle = window.getComputedStyle(t,null);
16− var realW = cStyle.getPropertyValue("width").slice(0,-2) - 0;
17− var realH = cStyle.getPropertyValue("height").slice(0,-2) - 0;
18− document.body.removeChild(t);
19− //delete t;
20− return { width: realW|0, height: realH|0 };
21− }
22−
23− // This should not be useful, right?
24− function nodeSize(e) {
25− var t = e.cloneNode(true);
26−
27− t.style.visibility = "hidden";
28− t.style.styleFloat = "left";
29− t.style.cssFloat = "left";
30−
31− document.body.appendChild(t);
32− var w = t.offsetWidth;
33− var h = t.offsetHeight;
34− document.body.removeChild(t);
35− //delete t;
36− return [w,h];
37− }
38−
39− return { htmlSize: htmlSize };
40−}();