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 Color = Elm.Native.Graphics.Color(elm);
11 var Element = Elm.Graphics.Element(elm);
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 properEscape(JS.fromString(str)); }
56 function addTag(tag) { return function(text) {
57 return '<' + tag + ' style="padding:0;margin:0">' + text + '</' + tag + '>';
61 function addStyle(style, value, text) {
62 return "<span style='" + style + ":" + value + "'>" + text + "</span>";
65 function typeface(name, text) {
66 return addStyle('font-family', JS.fromString(name), text);
68 function size(px, text) { return addStyle('font-size', px + 'px', text) }
69 var header = addTag('h1');
70 function height(h, text) { return addStyle('font-size', hf+'em', text) }
71 function italic(text) { return addStyle('font-style', 'italic', text) }
72 var bold = addTag('b');
73 function color(c, text) {
74 return addStyle('color', Color.extract(c), text);
76 function underline(text) { return addStyle('text-decoration', 'underline', text) }
77 function overline(text) { return addStyle('text-decoration', 'overline', text) }
78 function strikeThrough(text) {
79 return addStyle('text-decoration', 'line-through', text);
81 function link(href, text) {
82 return "<a href='" + toText(href) + "'>" + text + "</a>";
85 function position(pos) { return function(text) {
86 var e = {ctor:'RawHtml',
87 _0: '<div style="padding:0;margin:0;text-align:'+pos+'">'+text+'</div>'
89 return A3(Element.newElement, 0, 0, e);
94 return position('left')(typeface('monospace', toText(show(v))));
97 return elm.Native.Graphics.Text = {
104 underline : underline,
106 strikeThrough : strikeThrough,
107 monospace : function(text) { return typeface('monospace', text) },
108 typeface : F2(typeface),
112 justified : position('justify'),
113 centered : position('center'),
114 righted : position('right'),
115 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