2Elm.Native.Graphics.Text = function(elm) {
5 elm.Native = elm.Native || {};
6 elm.Native.Graphics = elm.Native.Graphics || {};
7 if (elm.Native.Graphics.Text) return elm.Native.Graphics.Text;
9 var JS = Elm.JavaScript(elm);
10 var htmlHeight = Elm.Native.Utils(elm).htmlHeight;
11 var Color = Elm.Native.Graphics.Color(elm);
12 var Element = Elm.Graphics.Element(elm);
14 function makeSpaces(s) {
15 if (s.length == 0) { return s; }
16 var arr = s.split('');
17 if (arr[0] == ' ') { arr[0] = " " }
18 for (var i = arr.length; --i; ) {
19 if (arr[i][0] == ' ' && arr[i-1] == ' ') {
20 arr[i-1] = arr[i-1] + arr[i];
24 for (var i = arr.length; i--; ) {
25 if (arr[i].length > 1 && arr[i][0] == ' ') {
26 var spaces = arr[i].split('');
27 for (var j = spaces.length - 2; j >= 0; j -= 2) {
30 arr[i] = spaces.join('');
34 if (arr[arr.length-1] === " ") {
35 return arr.slice(0,-1) + ' ';
40 function properEscape(str) {
41 if (str.length == 0) return str;
42 str = str //.replace(/&/g, "&")
43 .replace(/"/g, /*"*/ '"')
44 .replace(/'/g, /*'*/ "'")
45 .replace(/</g, "<")
46 .replace(/>/g, ">")
47 .replace(/\n/g, "<br/>");
48 var arr = str.split('<br/>');
49 for (var i = arr.length; i--; ) {
50 arr[i] = makeSpaces(arr[i]);
52 return arr.join('<br/>');
55 function toText(str) { return properEscape(JS.fromString(str)); }
57 function addTag(tag) { return function(text) {
58 return '<' + tag + ' style="padding:0;margin:0">' + text + '</' + tag + '>';
62 function addStyle(style, value, text) {
63 return "<span style='" + style + ":" + value + "'>" + text + "</span>";
66 function typeface(name, text) {
67 return addStyle('font-family', JS.fromString(name), text);
69 function size(px, text) { return addStyle('font-size', px + 'px', text) }
70 var header = addTag('h1');
71 function height(h, text) { return addStyle('font-size', hf+'em', text) }
72 function italic(text) { return addStyle('font-style', 'italic', text) }
73 var bold = addTag('b');
74 function color(c, text) {
75 return addStyle('color', Color.extract(c), text);
77 function underline(text) { return addStyle('text-decoration', 'underline', text) }
78 function overline(text) { return addStyle('text-decoration', 'overline', text) }
79 function strikeThrough(text) {
80 return addStyle('text-decoration', 'line-through', text);
82 function link(href, text) {
83 return "<a href='" + toText(href) + "'>" + text + "</a>";
86 function position(pos) { return function(text) {
87 var e = {ctor:'RawHtml',
88 _0: '<div style="padding:0;margin:0;text-align:' +
89 pos + '">' + text + '</div>'
91 var w = elm.node.clientWidth;
92 return A3(Element.newElement, w, A2(htmlHeight, w, text), e);
97 return position('left')(typeface('monospace', toText(show(v))));
100 return elm.Native.Graphics.Text = {
107 underline : underline,
109 strikeThrough : strikeThrough,
110 monospace : function(text) { return typeface('monospace', text) },
111 typeface : F2(typeface),
115 justified : position('justify'),
116 centered : position('center'),
117 righted : position('right'),
118 text : position('left'),
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