2Elm.Native.Text.make = function(elm) {
3 elm.Native = elm.Native || {};
4 if (elm.Native.Text) return elm.Native.Text;
6 var JS = Elm.JavaScript.make(elm);
7 var htmlHeight = Elm.Native.Utils.make(elm).htmlHeight;
8 var Color = Elm.Native.Color.make(elm);
9 var Element = Elm.Graphics.Element.make(elm);
10 var show = Elm.Native.Show.make(elm).show;
12 function makeSpaces(s) {
13 if (s.length == 0) { return s; }
14 var arr = s.split('');
15 if (arr[0] == ' ') { arr[0] = " " }
16 for (var i = arr.length; --i; ) {
17 if (arr[i][0] == ' ' && arr[i-1] == ' ') {
18 arr[i-1] = arr[i-1] + arr[i];
22 for (var i = arr.length; i--; ) {
23 if (arr[i].length > 1 && arr[i][0] == ' ') {
24 var spaces = arr[i].split('');
25 for (var j = spaces.length - 2; j >= 0; j -= 2) {
28 arr[i] = spaces.join('');
32 if (arr[arr.length-1] === " ") {
33 return arr.slice(0,-1) + ' ';
38 function properEscape(str) {
39 if (str.length == 0) return str;
40 str = str //.replace(/&/g, "&")
41 .replace(/"/g, /*"*/ '"')
42 .replace(/'/g, /*'*/ "'")
43 .replace(/</g, "<")
44 .replace(/>/g, ">")
45 .replace(/\n/g, "<br/>");
46 var arr = str.split('<br/>');
47 for (var i = arr.length; i--; ) {
48 arr[i] = makeSpaces(arr[i]);
50 return arr.join('<br/>');
53 function toText(str) { return properEscape(JS.fromString(str)); }
55 function addTag(tag) { return function(text) {
56 return '<' + tag + ' style="padding:0;margin:0">' + text + '</' + tag + '>';
60 function addStyle(style, value, text) {
61 return "<span style='" + style + ":" + value + "'>" + text + "</span>";
64 function typeface(name, text) {
65 return addStyle('font-family', JS.fromString(name), text);
67 function monospace(text) {
68 return addStyle('font-family', 'monospace', text);
70 function size(px, text) { return addStyle('font-size', px + 'px', text) }
71 var header = addTag('h1');
72 function height(h, text) { return addStyle('font-size', h+'px', text) }
73 function italic(text) { return addStyle('font-style', 'italic', text) }
74 var bold = addTag('b');
77 if (c._3 === 1) { return 'rgb(' + c._0 + ',' + c._1 + ',' + c._2 + ')'; }
78 return 'rgba(' + c._0 + ',' + c._1 + ',' + c._2 + ',' + c._3 + ')';
80 function color(c, text) {
81 return addStyle('color', extract(c), text);
83 function underline(text) { return addStyle('text-decoration', 'underline', text) }
84 function overline(text) { return addStyle('text-decoration', 'overline', text) }
85 function strikeThrough(text) {
86 return addStyle('text-decoration', 'line-through', text);
88 function link(href, text) {
89 return "<a href='" + toText(href) + "'>" + text + "</a>";
92 function position(pos) {
93 return function(text) {
94 var e = {ctor:'RawHtml',
95 _0: '<div style="padding:0;margin:0;text-align:' +
96 pos + '">' + text + '</div>'
98 var p = A2(htmlHeight, 0, text);
99 return A3(Element.newElement, p._0, p._1, e);
104 return position('left')(monospace(toText(show(v))));
107 function plainText(v) {
108 return position('left')(toText(v));
111 return elm.Native.Text = {
118 underline : underline,
120 strikeThrough : strikeThrough,
121 monospace : monospace,
122 typeface : F2(typeface),
126 justified : position('justify'),
127 centered : position('center'),
128 righted : position('right'),
129 text : position('left'),
130 plainText : plainText,
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list