2Elm.Native.Text.make = function(elm) {
3 elm.Native = elm.Native || {};
4 elm.Native.Text = elm.Native.Text || {};
5 if (elm.Native.Text.values) return elm.Native.Text.values;
7 var Element = Elm.Graphics.Element.make(elm);
8 var List = Elm.Native.List.make(elm);
9 var Utils = Elm.Native.Utils.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 Utils.txt(properEscape(str)); }
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 + "'";
64 return typefaces.join(',');
66 function toLine(line) {
68 var decoration = ctor === 'Under' ? 'underline' :
69 ctor === 'Over' ? 'overline' : 'line-through';
70 return 'text-decoration:' + decoration + ';';
73 var color = (c._3 === 1)
74 ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
75 : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
76 return 'color:' + color + ';';
79 // setting styles of Text
80 function style(style, text) {
81 var newText = '<span style="' + toColor(style.color);
82 if (style.typeface.ctor !== '[]') {
83 newText += 'font-family:' + toTypefaces(style.typeface) + ';'
85 if (style.height.ctor !== "Nothing") {
86 newText += 'font-size:' + style.height._0 + 'px;';
89 newText += 'font-weight:bold;';
92 newText += 'font-style:italic;';
94 if (style.line.ctor !== 'Nothing') {
95 newText += toLine(style.line._0);
97 newText += '">' + Utils.makeText(text) + '</span>'
98 return Utils.txt(newText);
100 function height(px, text) {
101 return { style: 'font-size:' + px + 'px;', text:text }
103 function typeface(names, text) {
104 return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
106 function monospace(text) {
107 return { style: 'font-family:monospace;', text:text }
109 function italic(text) {
110 return { style: 'font-style:italic;', text:text }
112 function bold(text) {
113 return { style: 'font-weight:bold;', text:text }
115 function link(href, text) {
116 return { href: toText(href), text:text };
118 function line(line, text) {
119 return { style: toLine(line), text:text };
122 function color(c, text) {
123 var color = (c._3 === 1)
124 ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
125 : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
126 return { style: 'color:' + color + ';', text:text };
129 function block(align) {
130 return function(text) {
133 html : Utils.makeText(text),
138 var pos = A2(Utils.htmlHeight, 0, raw);
139 return A3(Element.newElement, pos._0, pos._1, raw);
143 function markdown(text, guid) {
151 var pos = A2(Utils.htmlHeight, 0, raw);
152 return A3(Element.newElement, pos._0, pos._1, raw);
155 return elm.Native.Text.values = {
162 monospace : monospace,
163 typeface : F2(typeface),
167 leftAligned : block('left'),
168 rightAligned : block('right'),
169 centered : block('center'),
170 justified : block('justify'),
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