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 Color = Elm.Native.Color.make(elm);
8 var Element = Elm.Graphics.Element.make(elm);
9 var List = Elm.Native.List.make(elm);
10 var Utils = Elm.Native.Utils.make(elm);
11 var show = Elm.Native.Show.make(elm).show;
13 function makeSpaces(s) {
14 if (s.length == 0) { return s; }
15 var arr = s.split('');
16 if (arr[0] == ' ') { arr[0] = " " }
17 for (var i = arr.length; --i; ) {
18 if (arr[i][0] == ' ' && arr[i-1] == ' ') {
19 arr[i-1] = arr[i-1] + arr[i];
23 for (var i = arr.length; i--; ) {
24 if (arr[i].length > 1 && arr[i][0] == ' ') {
25 var spaces = arr[i].split('');
26 for (var j = spaces.length - 2; j >= 0; j -= 2) {
29 arr[i] = spaces.join('');
33 if (arr[arr.length-1] === " ") {
34 return arr.slice(0,-1) + ' ';
39 function properEscape(str) {
40 if (str.length == 0) return str;
41 str = str //.replace(/&/g, "&")
42 .replace(/"/g, '"')
43 .replace(/'/g, "'")
44 .replace(/</g, "<")
45 .replace(/>/g, ">")
46 .replace(/\n/g, "<br/>");
47 var arr = str.split('<br/>');
48 for (var i = arr.length; i--; ) {
49 arr[i] = makeSpaces(arr[i]);
51 return arr.join('<br/>');
54 function toText(str) { return Utils.txt(properEscape(str)); }
56 // conversions from Elm values to CSS
57 function toTypefaces(list) {
58 var typefaces = List.toArray(list);
59 for (var i = typefaces.length; i--; ) {
60 var typeface = typefaces[i];
61 if (typeface.contains(' ')) {
62 typefaces[i] = "'" + typeface + "'";
65 return typefaces.join(',');
67 function toLine(line) {
69 return ctor === 'Under' ? 'underline' :
70 ctor === 'Over' ? 'overline' : 'line-through';
73 // setting styles of Text
74 function style(style, text) {
75 var newText = '<span style="color:' + toCss(style.color) + ';'
76 if (style.typeface.ctor !== '[]') {
77 newText += 'font-family:' + toTypefaces(style.typeface) + ';'
79 if (style.height.ctor !== "Nothing") {
80 newText += 'font-size:' + style.height._0 + 'px;';
83 newText += 'font-weight:bold;';
86 newText += 'font-style:italic;';
88 if (style.line.ctor !== 'Nothing') {
89 newText += 'text-decoration:' + toLine(style.line._0) + ';';
91 newText += '">' + Utils.makeText(text) + '</span>'
92 return Utils.txt(newText);
94 function height(px, text) {
95 return { style: 'font-size:' + px + 'px;', text:text }
97 function typeface(names, text) {
98 return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
100 function monospace(text) {
101 return { style: 'font-family:monospace;', text:text }
103 function italic(text) {
104 return { style: 'font-style:italic;', text:text }
106 function bold(text) {
107 return { style: 'font-weight:bold;', text:text }
109 function link(href, text) {
110 return { href: toText(href), text:text };
112 function line(line, text) {
113 return { style: 'text-decoration:' + toLine(line) + ';', text:text };
116 function color(color, text) {
117 return { style: 'color:' + toCss(color) + ';', text:text };
120 function block(align) {
121 return function(text) {
124 html : Utils.makeText(text),
129 var pos = A2(Utils.htmlHeight, 0, raw);
130 return A3(Element.newElement, pos._0, pos._1, raw);
134 function markdown(text, guid) {
142 var pos = A2(Utils.htmlHeight, 0, raw);
143 return A3(Element.newElement, pos._0, pos._1, raw);
146 return elm.Native.Text.values = {
153 monospace : monospace,
154 typeface : F2(typeface),
158 leftAligned : block('left'),
159 rightAligned : block('right'),
160 centered : block('center'),
161 justified : block('justify'),
164 toTypefaces:toTypefaces,
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