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');
46 var rectangle = function(w) { return function(h) {
47 var e = newElement('div');
49 e.style.width = w + "px";
50 e.style.height = h + "px";
55 var makeText = function(w) { return function(pos) { return function(txt) {
56 var e = newElement('div');
60 e.style.textAlign = pos;
61 if (w > 0) e.style.width = w + "px";
66 var correctTextSize = function(e) {
67 var w = e.style.width ? e.style.width.slice(0,-2) : 0;
69 var t = newElement('div');
70 t.innerHTML = e.innerHTML;
71 t.style.textAlign = e.style.textAlign;
72 if (w > 0) { t.style.width = w + "px"; }
74 t.style.visibility = "hidden";
75 t.style.styleFloat = "left";
76 t.style.cssFloat = "left";
78 document.body.appendChild(t);
79 var cStyle = window.getComputedStyle(t);
80 if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
81 e.style.height = cStyle.getPropertyValue("height");
82 document.body.removeChild(t);
85 var link = function (href) { return function (e) {
86 var a = newElement('a');
87 a.href = Text.fromString(href);
93 var text = makeText(0)('left');
94 var plainText = function(str) {
95 return makeText(0)("left")(Data.String.toText(str)); };
96 var justifiedText = makeText(0)('justify');
97 var centeredText = makeText(0)('center');
98 var rightedText = makeText(0)('right');
99 var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
101 var image = function(src) {
102 var img = newElement('img');
103 img.isElmLeaf = true;
104 img.onload = function() {
105 if (img.style.width === "" && this.width > 0) {
106 img.style.width = img.width = this.width + "px";
108 if (img.style.height === "" && this.height > 0) {
109 img.style.height = img.height = this.height + "px";
113 img.src = Data.String.toText(src);
117 var fittedImage = function(w) { return function(h) { return function(src) {
118 var canvas = newElement('canvas');
119 canvas.style.width = w + 'px';
120 canvas.style.height = h + 'px';
123 canvas.innerHTML = "Your browser does not support the canvas element.";
124 canvas.isElmLeaf = true;
126 var img = newElement('img');
127 img.onload = function() {
128 if (canvas.getContext) {
129 var ctx = canvas.getContext('2d');
130 var sx = 0, sy = 0, sWidth = this.width, sHeight = this.height;
131 if (w / h > this.width / this.height) {
132 sHeight = this.width * h / w;
133 sy = (this.height - sHeight) / 2
135 sWidth = this.height * w / h;
136 sx = (this.width - sWidth) / 2
138 ctx.drawImage(img, sx, sy, sWidth, sHeight,
139 0,0, canvas.width, canvas.height);
142 img.src = Data.String.toText(src);
148 var video = function(src) {
149 src = Data.String.toText(src);
150 var e = newElement('video');
151 e.controls = "controls";
152 var source = newElement('source');
154 source.type = "video/" + src.substring(src.length - 3, src.length);
159 var audio = function(src) {
160 src = Data.String.toString(src);
161 var e = newElement('video');
162 e.controls = "controls";
163 var source = newElement('source');
165 source.type = "audio/" + src.substring(src.length - 3, src.length);
170 var collage = function(w) { return function(h) { return function(cflist) {
171 var canvas = newElement('canvas');
172 canvas.style.width = w + 'px';
173 canvas.style.height = h + 'px';
176 if (canvas.getContext) {
177 var ctx = canvas.getContext('2d');
178 ctx.clearRect(0,0, canvas.width, canvas.height);
179 while (cflist[0] === "Cons") {
180 ctx = cflist[1](ctx);
185 canvas.innerHTML = "Your browser does not support the canvas element.";
186 canvas.isElmLeaf = true;
192 var goDown = function(e) {
193 return e.tagName === "DIV" ? e : divify(e);
195 var goRight = function(e) {
196 e.style.styleFloat = "left";
197 e.style.cssFloat = "left";
200 var goIn = function(e) {
201 e.style.position = 'absolute';
204 var flowWith = function(dir, f, elist) {
205 var container = newElement('div');
206 for (var i = elist.length; i--; ) {
207 addTo(container, f(elist[i]));
209 container.elmFlowDirection = dir;
213 var flow = function(direction) { return function(elist) {
215 while (elist[0] === "Cons") {
219 if (direction >= 3) arr.reverse();
220 var f = function(x) { return x; };
221 var dir = direction % 3;
222 if (dir == 0) return flowWith("Y", goDown , arr);
223 if (dir == 1) return flowWith("X", goRight, arr);
224 if (dir == 2) return flowWith("Z", goIn , arr);
228 var beside = function(a) { return function(b) {
229 return flow(4)(["Cons",a,["Cons",b,["Nil"]]]); }; };
230 var above = function(a) { return function(b) {
231 return flow(3)(["Cons",a,["Cons",b,["Nil"]]]); }; };
232 var below = function(a) { return function(b) {
233 return flow(0)(["Cons",a,["Cons",b,["Nil"]]]); }; };
235 var box = function(pos) { return function(e) {
236 e.style.position = "absolute";
237 e.style.margin = "auto";
238 var x = (pos - 1) % 3;
239 var y = (pos - 1) / 3;
240 if (x < 2) e.style.left = 0;
241 if (x > 0) e.style.right = 0;
242 if (y < 2) e.style.top = 0;
243 if (y > 0) e.style.bottom = 0;
244 var div = newElement('div');
245 div.style.position = "relative";
251 var width = function(w) { return function(e) {
252 if (e.tagName === "A") {
253 width(w)(e.firstChild);
256 if (e.hasOwnProperty('isElmText')) {
257 var d = makeText(w)(e.style.textAlign)(e.innerHTML);
258 e.style.height = d.style.height;
260 e.style.width = w + "px";
264 var height = function(h) { return function(e) {
265 (e.tagName === "A" ? e.firstChild : e).style.height = h + "px";
269 var size = function(w) { return function(h) { return function(e) {
270 var d = e.tagName === "A" ? e.firstChild : e;
271 d.style.width = w + "px";
272 d.style.height = h + "px";
278 var color = function(c) { return function(e) {
279 e.style.backgroundColor = Color.Internal.extract(c);
283 var opacity = function(value) { return function(e) {
284 e.style.opacity = value;
291 fittedImage : fittedImage,
297 rectangle : rectangle,
312 plainText : plainText,
313 justifiedText : justifiedText,
314 centeredText : centeredText,
315 rightedText : rightedText,
325 correctTextSize : correctTextSize
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