on 09bbada help sign in
elk/core-js/Text.js
50 lines 1.6 kB history raw
2var Elm = Elm || {};
3Elm.Text = function() {
4 function fromString(s) { return Value.toText(s); }
6 var addTag = function(tag) { return function(text) {
7 return '<' + tag + ' style="padding:0;margin:0">' + text + '</' + tag + '>';
8 };
9 };
10 var addStyle = function(style, value) { return function(text) {
11 return "<span style='" + style + ":" + value + "'>" + text + "</span>";
12 };
13 };
15 var typeface = function(name) {
16 name = Elm.JavaScript.castStringToJSString(name);
17 return addStyle('font-family', name);
18 };
19 var size = function(px) {
20 return addStyle('font-size', px + 'px');
21 };
22 var header = addTag('h1');
23 var height = function(h) { return addStyle('font-size', h+'em'); }
24 var italic = addStyle('font-style', 'italic');
25 var bold = addTag('b');
26 var color = function(c) {
27 return addStyle('color', Elm.Color.extract(c));
28 };
29 var underline = addStyle('text-decoration', 'underline');
30 var overline = addStyle('text-decoration', 'overline');
31 var strikeThrough = addStyle('text-decoration', 'line-through');
32 var link = function(href) { return function(text) {
33 return "<a href='" + fromString(href) + "'>" + text + "</a>";
34 };
35 };
37 return {fromString : fromString,
38 toText: fromString,
39 header : header,
40 height : height,
41 italic : italic,
42 bold : bold,
43 underline : underline,
44 overline : overline,
45 strikeThrough : strikeThrough,
46 monospace : typeface('monospace'),
47 typeface : typeface,
48 color : color,
49 link : link };
50}();