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 toCss = Elm.Native.Color.make(elm).toCss;
8 var Element = Elm.Graphics.Element.make(elm);
9 var List = Elm.Native.List.make(elm);
10 var Utils = Elm.Native.Utils.make(elm);
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.indexOf(' ') > -1) {
61 typefaces[i] = "'" + typeface + "'";
64 return typefaces.join(',');
66 function toLine(line) {
68 return ctor === 'Under' ? 'underline' :
69 ctor === 'Over' ? 'overline' : 'line-through';
72 // setting styles of Text
73 function style(style, text) {
74 var newText = '<span style="color:' + toCss(style.color) + ';'
75 if (style.typeface.ctor !== '[]') {
76 newText += 'font-family:' + toTypefaces(style.typeface) + ';'
78 if (style.height.ctor !== "Nothing") {
79 newText += 'font-size:' + style.height._0 + 'px;';
82 newText += 'font-weight:bold;';
85 newText += 'font-style:italic;';
87 if (style.line.ctor !== 'Nothing') {
88 newText += 'text-decoration:' + toLine(style.line._0) + ';';
90 newText += '">' + Utils.makeText(text) + '</span>'
91 return Utils.txt(newText);
93 function height(px, text) {
94 return { style: 'font-size:' + px + 'px;', text:text }
96 function typeface(names, text) {
97 return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
99 function monospace(text) {
100 return { style: 'font-family:monospace;', text:text }
102 function italic(text) {
103 return { style: 'font-style:italic;', text:text }
105 function bold(text) {
106 return { style: 'font-weight:bold;', text:text }
108 function link(href, text) {
109 return { href: toText(href), text:text };
111 function line(line, text) {
112 return { style: 'text-decoration:' + toLine(line) + ';', text:text };
115 function color(color, text) {
116 return { style: 'color:' + toCss(color) + ';', text:text };
119 function block(align) {
120 return function(text) {
123 html : Utils.makeText(text),
128 var pos = A2(Utils.htmlHeight, 0, raw);
129 return A3(Element.newElement, pos._0, pos._1, raw);
133 function markdown(text, guid) {
141 var pos = A2(Utils.htmlHeight, 0, raw);
142 return A3(Element.newElement, pos._0, pos._1, raw);
145 return elm.Native.Text.values = {
152 monospace : monospace,
153 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