@@ -4,11 +4,10 @@ Elm.Native.Text.make = function(elm) {
44 elm.Native.Text = elm.Native.Text || {};
55 if (elm.Native.Text.values) return elm.Native.Text.values;
66
7− var JS = Elm.JavaScript.make(elm);
8− var Utils = Elm.Native.Utils.make(elm);
9− var Color = Elm.Native.Color.make(elm);
7+ var toCss = Elm.Native.Color.make(elm).toCss;
108 var Element = Elm.Graphics.Element.make(elm);
11− var show = Elm.Native.Show.make(elm).show;
9+ var List = Elm.Native.List.make(elm);
10+ var Utils = Elm.Native.Utils.make(elm);
1211
1312 function makeSpaces(s) {
1413 if (s.length == 0) { return s; }
@@ -51,13 +50,51 @@ Elm.Native.Text.make = function(elm) {
5150 return arr.join('<br/>');
5251 }
5352
54− function toText(str) { return Utils.txt(properEscape(JS.fromString(str))); }
53+ function toText(str) { return Utils.txt(properEscape(str)); }
54+
55+ // conversions from Elm values to CSS
56+ function toTypefaces(list) {
57+ var typefaces = List.toArray(list);
58+ for (var i = typefaces.length; i--; ) {
59+ var typeface = typefaces[i];
60+ if (typeface.contains(' ')) {
61+ typefaces[i] = "'" + typeface + "'";
62+ }
63+ }
64+ return typefaces.join(',');
65+ }
66+ function toLine(line) {
67+ var ctor = line.ctor;
68+ return ctor === 'Under' ? 'underline' :
69+ ctor === 'Over' ? 'overline' : 'line-through';
70+ }
5571
72+ // setting styles of Text
73+ function style(style, text) {
74+ var newText = '<span style="color:' + toCss(style.color) + ';'
75+ if (style.typeface.ctor !== '[]') {
76+ newText += 'font-family:' + toTypefaces(style.typeface) + ';'
77+ }
78+ if (style.height.ctor !== "Nothing") {
79+ newText += 'font-size:' + style.height._0 + 'px;';
80+ }
81+ if (style.bold) {
82+ newText += 'font-weight:bold;';
83+ }
84+ if (style.italic) {
85+ newText += 'font-style:italic;';
86+ }
87+ if (style.line.ctor !== 'Nothing') {
88+ newText += 'text-decoration:' + toLine(style.line._0) + ';';
89+ }
90+ newText += '">' + Utils.makeText(text) + '</span>'
91+ return Utils.txt(newText);
92+ }
5693 function height(px, text) {
5794 return { style: 'font-size:' + px + 'px;', text:text }
5895 }
59− function typeface(name, text) {
60− return { style: 'font-family:' + name + ';', text:text }
96+ function typeface(names, text) {
97+ return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
6198 }
6299 function monospace(text) {
63100 return { style: 'font-family:monospace;', text:text }
@@ -71,25 +108,16 @@ Elm.Native.Text.make = function(elm) {
71108 function link(href, text) {
72109 return { href: toText(href), text:text };
73110 }
74− function underline(text) {
75− return { line: ' underline', text:text };
76− }
77− function overline(text) {
78− return { line: ' overline', text:text };
79− }
80− function strikeThrough(text) {
81− return { line: ' line-through', text:text };
111+ function line(line, text) {
112+ return { style: 'text-decoration:' + toLine(line) + ';', text:text };
82113 }
83114
84− function color(c, text) {
85− var color = (c._3 === 1)
86− ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
87− : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
88− return { style: 'color:' + color + ';', text:text };
115+ function color(color, text) {
116+ return { style: 'color:' + toCss(color) + ';', text:text };
89117 }
90118
91− function position(align) {
92− function create(text) {
119+ function block(align) {
120+ return function(text) {
93121 var raw = {
94122 ctor :'RawHtml',
95123 html : Utils.makeText(text),
@@ -100,7 +128,6 @@ Elm.Native.Text.make = function(elm) {
100128 var pos = A2(Utils.htmlHeight, 0, raw);
101129 return A3(Element.newElement, pos._0, pos._1, raw);
102130 }
103− return create;
104131 }
105132
106133 function markdown(text, guid) {
@@ -115,36 +142,25 @@ Elm.Native.Text.make = function(elm) {
115142 return A3(Element.newElement, pos._0, pos._1, raw);
116143 }
117144
118− var text = position('left');
119− function asText(v) {
120− return text(monospace(toText(show(v))));
121− }
122−
123− function plainText(v) {
124− return text(toText(v));
125− }
126−
127145 return elm.Native.Text.values = {
128146 toText: toText,
129147
130148 height : F2(height),
131149 italic : italic,
132150 bold : bold,
133− underline : underline,
134− overline : overline,
135− strikeThrough : strikeThrough,
151+ line : F2(line),
136152 monospace : monospace,
137153 typeface : F2(typeface),
138154 color : F2(color),
139155 link : F2(link),
140156
141− justified : position('justify'),
142− centered : position('center'),
143− righted : position('right'),
144− text : text,
145− plainText : plainText,
146− markdown : markdown,
157+ leftAligned : block('left'),
158+ rightAligned : block('right'),
159+ centered : block('center'),
160+ justified : block('justify'),
161+ markdown : markdown,
147162
148− asText : asText,
163+ toTypefaces:toTypefaces,
164+ toLine:toLine,
149165 };
150166};