2var Element = function() {
3 var newElement = function(elementType) {
4 var e = document.createElement(elementType);
9 var addTo = function(container, elem) {
10 container.appendChild(clone(elem));
11 //elem.timesAdded += 1;
13 var clone = function(e) {
15 /*if (e.timesAdded === 0) { return e; }
16 if (e.tagName === "CANVAS") {
17 var newCanvas = e.cloneNode(true);
18 var ctx = newCanvas.getContext('2d');
19 ctx.drawImage(e, 0, 0);
21 } else if (e.tagName === "IMG") {
25 if (e.style.width !== "") { d.style.width = d.width = e.style.width; }
26 if (e.style.height !== ""){d.style.height = d.height = e.style.height;}
28 } else if (e.hasOwnProperty('isElmLeaf')) {
29 return e.cloneNode(true);
31 d = e.cloneNode(false);
32 var kids = e.childNodes;
33 var len = kids.length;
34 for (var i = 0; i < len; i++) {
35 d.appendChild(clone(kids[i]));
40 var divify = function(e) {
41 var div = newElement('div');
45 var makeText = function(w) { return function(pos) { return function(txt) {
46 var e = newElement('div');
49 e.style.textAlign = pos;
50 if (w > 0) e.style.width = w + "px";
52 e.style.visibility = "hidden";
53 e.style.styleFloat = "left";
54 e.style.cssFloat = "left";
55 document.body.appendChild(e);
56 var cStyle = window.getComputedStyle(e);
57 if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
58 e.style.height = cStyle.getPropertyValue("height");
59 document.body.removeChild(e);
60 e.style.visibility = "visible"
61 e.style.styleFloat = "none";
62 e.style.cssFloat = "none";
67 var link = function (href) { return function (e) {
68 var a = newElement('a');
69 a.href = Text.fromString(href);
75 var text = makeText(0)('left');
76 var plainText = function(str) {
77 return makeText(0)("left")(String.toText(str)); };
78 var justifiedText = makeText(0)('justify');
79 var centeredText = makeText(0)('center');
80 var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
82 var image = function(src) {
83 var img = newElement('img');
85 img.onload = function() {
86 if (img.style.width === "" && this.width > 0) {
87 img.style.width = img.width = this.width + "px";
89 if (img.style.height === "" && this.height > 0) {
90 img.style.height = img.height = this.height + "px";
94 img.src = String.toText(src);
98 var video = function(src) {
99 src = String.toText(src);
100 var e = newElement('video');
101 e.controls = "controls";
102 var source = newElement('source');
104 source.type = "video/" + src.substring(src.length - 3, src.length);
109 var audio = function(src) {
110 src = String.toString(src);
111 var e = newElement('video');
112 e.controls = "controls";
113 var source = newElement('source');
115 source.type = "audio/" + src.substring(src.length - 3, src.length);
120 var collage = function(w) { return function(h) { return function(cflist) {
121 var canvas = newElement('canvas');
122 canvas.style.width = w + 'px';
123 canvas.style.height = h + 'px';
126 if (canvas.getContext) {
127 var ctx = canvas.getContext('2d');
128 ctx.clearRect(0,0, canvas.width, canvas.height);
129 while (cflist[0] === "Cons") {
130 ctx = cflist[1](ctx);
135 canvas.innerHTML = "Your browser does not support the canvas element.";
136 canvas.isElmLeaf = true;
142 var goDown = function(e) {
143 return e.tagName === "DIV" ? e : divify(e);
145 var goRight = function(e) {
146 e.style.styleFloat = "left";
147 e.style.cssFloat = "left";
150 var goIn = function(e) {
151 e.style.position = 'absolute';
154 var flowWith = function(dir, f, elist) {
155 var container = newElement('div');
156 for (var i = elist.length; i--; ) {
157 addTo(container, f(elist[i]));
159 container.elmFlowDirection = dir;
163 var flow = function(direction) { return function(elist) {
165 while (elist[0] === "Cons") {
169 if (direction >= 3) arr.reverse();
170 var f = function(x) { return x; };
171 var dir = direction % 3;
172 if (dir == 0) return flowWith("Y", goDown , arr);
173 if (dir == 1) return flowWith("X", goRight, arr);
174 if (dir == 2) return flowWith("Z", goIn , arr);
178 var beside = function(a) { return function(b) {
179 return flow(1)(["Cons",a,["Cons",b,["Nil"]]]); }; };
180 var above = function(a) { return function(b) {
181 return flow(0)(["Cons",a,["Cons",b,["Nil"]]]); }; };
182 var below = function(a) { return function(b) {
183 return flow(3)(["Cons",a,["Cons",b,["Nil"]]]); }; };
185 var box = function(pos) { return function(e) {
186 e.style.position = "absolute";
187 e.style.margin = "auto";
188 var x = (pos - 1) % 3;
189 var y = (pos - 1) / 3;
190 if (x < 2) e.style.left = 0;
191 if (x > 0) e.style.right = 0;
192 if (y < 2) e.style.top = 0;
193 if (y > 0) e.style.bottom = 0;
194 var div = newElement('div');
195 div.style.position = "relative";
201 var width = function(w) { return function(e) {
202 if (e.tagName === "A") {
203 width(w)(e.firstChild);
206 if (e.hasOwnProperty('isElmText')) {
207 var d = makeText(w)(e.style.textAlign)(e.innerHTML);
208 e.style.height = d.style.height;
210 e.style.width = w + "px";
214 var height = function(h) { return function(e) {
215 (e.tagName === "A" ? e.firstChild : e).style.height = h + "px";
219 var size = function(w) { return function(h) { return function(e) {
220 var d = e.tagName === "A" ? e.firstChild : e;
221 d.style.width = w + "px";
222 d.style.height = h + "px";
228 var color = function(c) { return function(e) {
229 e.style.backgroundColor = Color.Internal.extract(c);
233 var opacity = function(value) { return function(e) {
234 e.style.opacity = value;
260 plainText : plainText,
261 justifiedText : justifiedText,
262 centeredText : centeredText,
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