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