on master help sign in
Add all core JavaScript libraries.
commitff3d6ec6cb48c13817ab3157e7e41c95c8ebcd08 authorevancz <info@elm-lang.org> dateThu 19 Apr 2012, 23:10 (15 years ago) parenta587ff5
14 files changed+1583
core-js/Element.js+274 core-js/Everything.js+76 core-js/Guid.js+6 core-js/List.js+436 core-js/String.js+22 core-js/Text.js+52 core-js/Value.js+75 core-js/collage/Color.js+34 core-js/collage/Form.js+33 core-js/collage/Image.js+9 core-js/collage/Line.js+103 core-js/collage/Shape.js+110 core-js/runtime/Dispatcher.js+146 core-js/runtime/Signal.js+207
core-js/Element.jsnew file+274
@@ -0,0 +1,274 @@
1+
2+var Element = function() {
3+ var newElement = function(elementType) {
4+ var e = document.createElement(elementType);
5+ e.id = Guid.guid();
6+ //e.timesAdded = 0;
7+ return e;
8+ };
9+ var addTo = function(container, elem) {
10+ container.appendChild(clone(elem));
11+ //elem.timesAdded += 1;
12+ };
13+ var clone = function(e) {
14+ return 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);
20+ return newCanvas;
21+ } else if (e.tagName === "IMG") {
22+ d = image([]);
23+ d.src = e.src;
24+ d.name = e.name;
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;}
27+ return d;
28+ } else if (e.hasOwnProperty('isElmLeaf')) {
29+ return e.cloneNode(true);
30+ } else {
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]));
36+ }
37+ return d;
38+ }*/
39+ };
40+ var divify = function(e) {
41+ var div = newElement('div');
42+ addTo(div, e);
43+ return div;
44+ };
45+ var makeText = function(w) { return function(pos) { return function(txt) {
46+ var e = newElement('div');
47+ e.isElmText = true;
48+ e.innerHTML = txt;
49+ e.style.textAlign = pos;
50+ if (w > 0) e.style.width = w + "px";
51+ e.isElmLeaf = true;
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";
63+ return e;
64+ };
65+ };
66+ };
67+ var link = function (href) { return function (e) {
68+ var a = newElement('a');
69+ a.href = Text.fromString(href);
70+ addTo(a,e);
71+ return divify(a);
72+ };
73+ };
74+
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)); };
81+
82+ var image = function(src) {
83+ var img = newElement('img');
84+ img.isElmLeaf = true;
85+ img.onload = function() {
86+ if (img.style.width === "" && this.width > 0) {
87+ img.style.width = img.width = this.width + "px";
88+ }
89+ if (img.style.height === "" && this.height > 0) {
90+ img.style.height = img.height = this.height + "px";
91+ }
92+ Dispatcher.adjust()
93+ };
94+ img.src = String.toText(src);
95+ img.name = img.src;
96+ return img;
97+ };
98+ var video = function(src) {
99+ src = String.toText(src);
100+ var e = newElement('video');
101+ e.controls = "controls";
102+ var source = newElement('source');
103+ source.src = src;
104+ source.type = "video/" + src.substring(src.length - 3, src.length);
105+ addTo(e, source);
106+ e.isElmLeaf = true;
107+ return e;
108+ };
109+ var audio = function(src) {
110+ src = String.toString(src);
111+ var e = newElement('video');
112+ e.controls = "controls";
113+ var source = newElement('source');
114+ source.src = src;
115+ source.type = "audio/" + src.substring(src.length - 3, src.length);
116+ addTo(e, source);
117+ e.isElmLeaf = true;
118+ return e;
119+ };
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';
124+ canvas.width = w;
125+ canvas.height = h;
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);
131+ cflist = cflist[2];
132+ }
133+ return canvas;
134+ }
135+ canvas.innerHTML = "Your browser does not support the canvas element.";
136+ canvas.isElmLeaf = true;
137+ return canvas;
138+ };
139+ };
140+ };
141+
142+ var goDown = function(e) {
143+ return e.tagName === "DIV" ? e : divify(e);
144+ };
145+ var goRight = function(e) {
146+ e.style.styleFloat = "left";
147+ e.style.cssFloat = "left";
148+ return e;
149+ };
150+ var goIn = function(e) {
151+ e.style.position = 'absolute';
152+ return e;
153+ };
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]));
158+ }
159+ container.elmFlowDirection = dir;
160+ return container;
161+ };
162+
163+ var flow = function(direction) { return function(elist) {
164+ var arr = [];
165+ while (elist[0] === "Cons") {
166+ arr.push(elist[1]);
167+ elist = elist[2];
168+ }
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);
175+ };
176+ };
177+
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"]]]); }; };
184+
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";
196+ addTo(div,e);
197+ return div;
198+ };
199+ };
200+
201+ var width = function(w) { return function(e) {
202+ if (e.tagName === "A") {
203+ width(w)(e.firstChild);
204+ return e;
205+ }
206+ if (e.hasOwnProperty('isElmText')) {
207+ var d = makeText(w)(e.style.textAlign)(e.innerHTML);
208+ e.style.height = d.style.height;
209+ }
210+ e.style.width = w + "px";
211+ return e;
212+ };
213+ };
214+ var height = function(h) { return function(e) {
215+ (e.tagName === "A" ? e.firstChild : e).style.height = h + "px";
216+ return e;
217+ };
218+ };
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";
223+ return e;
224+ };
225+ };
226+ };
227+
228+ var color = function(c) { return function(e) {
229+ e.style.backgroundColor = Color.Internal.extract(c);
230+ return e;
231+ };
232+ };
233+ var opacity = function(value) { return function(e) {
234+ e.style.opacity = value;
235+ return e;
236+ };
237+ };
238+
239+ return {text : text,
240+ image : image,
241+ video : video,
242+ audio : audio,
243+ collage : collage,
244+ flow : flow,
245+ layers : flow(2),
246+
247+ beside : beside,
248+ above : above,
249+ below : below,
250+ box : box,
251+
252+ width : width,
253+ height : height,
254+ size : size,
255+ color : color,
256+ opacity : opacity,
257+
258+ link : link,
259+ asText : asText,
260+ plainText : plainText,
261+ justifiedText : justifiedText,
262+ centeredText : centeredText,
263+
264+ // directions
265+ up : 0,
266+ left : 1,
267+ inward : 2,
268+ down : 3,
269+ right : 4,
270+ outward : 5
271+ };
272+}();
273+
274+
core-js/Everything.jsnew file+76
@@ -0,0 +1,76 @@
1+
2+var id = function(x) { return x; };
3+var not = function(exp) { return !exp; };
4+
5+var sqrt = function(x) { return Math.sqrt(x); };
6+var mod = function(x) { return function(y) { return x % y; }; };
7+var abs = function(x) { return Math.abs(x); };
8+var logBase = function(base) { return function(x) { return Math.log(x) / Math.log(base); }; };
9+
10+var min = function(x) { return function(y) { return Math.min(x,y); }; };
11+var max = function(x) { return function(y) { return Math.max(x,y); }; };
12+var clamp = function(lo) { return function(hi) {
13+ return function(x) { return Math.min(hi, Math.max(lo, x)); };
14+ };
15+};
16+
17+var sin = Math.sin, cos = Math.cos, tan = Math.tan;
18+var asin = Math.asin, acos = Math.acos, atan = Math.atan;
19+
20+var flip = function(f){return function(x){return function(y){return f(y)(x);};};};
21+
22+function constant(v) { return Elm.Input(v); }
23+function lift(f) { return function(e) { return Elm.Lift(f, [e]); }; }
24+function lift2(f) { return function(e1) { return function(e2) {
25+ return Elm.Lift(f, [e1,e2]); }; }; }
26+function lift3(f) { return function(e1) { return function(e2) {
27+ return function(e3) { return Elm.Lift(f, [e1,e2,e3]); }; }; }; }
28+function lift4(f) { return function(e1) { return function(e2) {
29+ return function(e3) { return function(e4) {
30+ return Elm.Lift(f, [e1,e2,e3,e4]); }; }; }; }; }
31+function foldp(f) { return function(b) { return function(e) {
32+ return Elm.Fold(f,b,e); }; }; }
33+
34+
35+var includeGlobal = this;
36+(function() {
37+ var include = function(library) {
38+ for (var i in library) {
39+ if (i === 'Internal') continue;
40+ try {
41+ includeGlobal[i] = library[i];
42+ } catch (err) {
43+ if (i === 'length') {
44+ includeGlobal.execScript('var length;');
45+ length = library[i];
46+ continue;
47+ }
48+ }
49+ }
50+ };
51+ var includeAs = function(name) { return function(library) {
52+ includeGlobal[name] = includeGlobal[name] || {};
53+ for (var i in library) {
54+ if (i === 'Internal') continue;
55+ includeGlobal[name][i] = library[i];
56+ }
57+ };
58+ };
59+ include (Element);
60+ include (Text);
61+
62+ color = Element.color;
63+ height = Element.height;
64+ show = Value.show;
65+
66+ includeAs ('Time') (Signal.Time);
67+ includeAs ('Mouse') (Signal.Mouse);
68+ includeAs ('Window') (Signal.Window);
69+ includeAs ('HTTP') (Signal.HTTP);
70+ includeAs ('Input') (Signal.Input);
71+ includeAs ('Random') (Signal.Random);
72+
73+ include (Color);
74+ include (Shape);
75+ include (Line);
76+}());
core-js/Guid.jsnew file+6
@@ -0,0 +1,6 @@
1+
2+var Guid = function() {
3+ var counter = 0;
4+ var guid = function() { counter += 1; return counter; };
5+ return {guid : guid};
6+}();
core-js/List.jsnew file+436
@@ -0,0 +1,436 @@
1+var List = function() {
2+
3+ var throwError = function() { throw "Function expecting a list!"; }
4+
5+ function length(xs) {
6+ var out = 0;
7+ while (xs[0] === "Cons") {
8+ out += 1;
9+ xs = xs[2];
10+ }
11+ return out;
12+ };
13+ var reverse = foldl(function(x_72) {
14+ return function(y_73) {
15+ return["Cons", x_72, y_73]
16+ }
17+ })(["Nil"]);
18+ var concat = foldr(function(x_74) {
19+ return function(y_75) {
20+ return Value.append(x_74, y_75)
21+ }
22+ })(["Nil"]);
23+ var and = foldl(function(x_77) {
24+ return function(y_78) {
25+ return x_77 && y_78
26+ }
27+ })(true);
28+ var or = foldl(function(x_79) {
29+ return function(y_80) {
30+ return x_79 || y_80
31+ }
32+ })(false);
33+ var sum = foldl(function(x_89) {
34+ return function(y_90) {
35+ return x_89 + y_90
36+ }
37+ })(0);
38+ var product = foldl(function(x_91) {
39+ return function(y_92) {
40+ return x_91 * y_92
41+ }
42+ })(1);
43+ var maximum = foldl1(function(x) { return function(y) { return Math.max(x,y) } });
44+ var minimum = foldl1(function(x) { return function(y) { return Math.min(x,y) } });
45+ function head(v) {
46+ if (v[0] !== "Cons") {
47+ throw "Error: 'head' only accepts lists of length greater than one.";
48+ }
49+ return v[1];
50+ }
51+ function tail(v) {
52+ if (v[0] !== "Cons") {
53+ throw "Error: 'tail' only accepts lists of length greater than one.";
54+ }
55+ return v[2];
56+ }
57+ function map(f) {
58+ return function(xs) {
59+ if (xs[0] === "Nil") { return xs; }
60+ if (xs[0] !== "Cons") { throwError(); }
61+ var root = ["Cons", f(xs[1]), ["Nil"]];
62+ var curr = root;
63+ xs = xs[2];
64+ while (xs[0]==="Cons") {
65+ curr[2] = ["Cons", f(xs[1]), ["Nil"]];
66+ xs = xs[2];
67+ curr = curr[2];
68+ }
69+ return root;
70+ }
71+ }
72+ function foldl(f) {
73+ return function(b) {
74+ return function(xs) {
75+ var acc = b;
76+ if (xs[0] === "Nil") { return acc; }
77+ if (xs[0] !== "Cons") { throwError(); }
78+ while (xs[0] === "Cons") {
79+ acc = f(xs[1])(acc);
80+ xs = xs[2];
81+ }
82+ return acc;
83+ }
84+ }
85+ }
86+ function foldr(f) {
87+ return function(b) {
88+ return function(xs) {
89+ var acc = b;
90+ if (xs[0] === "Nil") { return acc; }
91+ if (xs[0] !== "Cons") { throwError(); }
92+ var arr = [];
93+ while (xs[0] === "Cons") {
94+ arr.push(xs[1]);
95+ xs = xs[2];
96+ }
97+ for (var i = arr.length; i--; ) {
98+ acc = f(arr[i])(acc);
99+ }
100+ return acc;
101+ }
102+ }
103+ }
104+ function foldl1(f_49) {
105+ return function(_temp_50) {
106+ return function(v) {
107+ if("Cons" !== v[0]) {
108+ return undefined
109+ }else {
110+ var x_51 = v[1];
111+ var xs_52 = v[2];
112+ return foldl(f_49)(x_51)(xs_52)
113+ }
114+ }(_temp_50)
115+ }
116+ }
117+ function foldr1(f_53) {
118+ return function(_temp_54) {
119+ return function(v) {
120+ if("Cons" !== v[0]) {
121+ return undefined
122+ }else {
123+ var x_55 = v[1];
124+ var xs_56 = v[2];
125+ return foldr(f_53)(x_55)(xs_56)
126+ }
127+ }(_temp_54)
128+ }
129+ }
130+ function scanl(f) {
131+ return function(b) {
132+ return function(xs) {
133+ if (xs[0] === "Nil") { return ["Cons",b,["Nil"]]; }
134+ if (xs[0] !== "Cons") { throwError(); }
135+ var arr = [b];
136+ while (xs[0] === "Cons") {
137+ b = f(xs[1])(b);
138+ arr.push(b);
139+ xs = xs[2];
140+ }
141+ var out = ["Nil"];
142+ for (var i = arr.length; i--; ) {
143+ out = ["Cons", arr[i], out];
144+ }
145+ return out;
146+ }
147+ }
148+ }
149+ function scanl1(f) {
150+ return function(xs) {
151+ if (xs[0] !== "Cons") {
152+ throw "Error: 'scanl1' requires a list of at least length 1.";
153+ }
154+ return scanl(f)(xs[1])(xs[2]);
155+ }
156+ }
157+ function filter(pred) {
158+ return function(xs) {
159+ if (xs[0] === "Nil") { return xs; }
160+ if (xs[0] !== "Cons") { throwError(); }
161+ var arr = [];
162+ while (xs[0] === "Cons") {
163+ if (pred(xs[1])) { arr.push(xs[1]); }
164+ xs = xs[2];
165+ }
166+ var out = ["Nil"];
167+ for (var i = arr.length; i--; ) {
168+ out = ["Cons", arr[i], out];
169+ }
170+ return out;
171+ }
172+ }
173+ function concatMap(f_76) {
174+ return function(x) {
175+ return concat(map(f_76)(x))
176+ }
177+ }
178+ function forall(pred) {
179+ return foldl(function(x) { return function(acc) {
180+ return acc && pred(x);
181+ };})(true);
182+ }
183+ function exists(pred) {
184+ return foldl(function(x) { return function(acc) {
185+ return acc || pred(x);
186+ };})(false);
187+ }
188+ function partition(pred_93) {
189+ return function(lst_94) {
190+ return function() {
191+ var v = lst_94;
192+ var c = [function(v) {
193+ if("Nil" !== v[0]) {
194+ return undefined
195+ }else {
196+ return["Tuple2", ["Nil"], ["Nil"]]
197+ }
198+ }, function(v) {
199+ if("Cons" !== v[0]) {
200+ return undefined
201+ }else {
202+ var x_95 = v[1];
203+ var xs_96 = v[2];
204+ return function(v) {
205+ if("Tuple2" !== v[0]) {
206+ return undefined
207+ }else {
208+ var as_97 = v[1];
209+ var bs_98 = v[2];
210+ return pred_93(x_95) ? ["Tuple2", ["Cons", x_95, as_97], bs_98] : ["Tuple2", as_97, ["Cons", x_95, bs_98]]
211+ }
212+ }(partition(pred_93)(xs_96))
213+ }
214+ }];
215+ for(var i = c.length;i--;) {
216+ var r = c[i](v);
217+ if(r !== undefined) {
218+ return r
219+ }
220+ }
221+ }()
222+ }
223+ }
224+ function zipWith(f) {
225+ return function(listA) {
226+ return function(listB) {
227+ if (listA[0] === "Nil" || listB[0] === "Nil") { return listA; }
228+ if (listA[0] !== "Cons" || listB[0] !== "Cons") { throwError(); }
229+ var arr = [];
230+ while (listA[0] === "Cons" && listB[0] === "Cons") {
231+ arr.push(f(listA[1])(listB[1]));
232+ listA = listA[2];
233+ listB = listB[2];
234+ }
235+ var out = ["Nil"];
236+ for (var i = arr.length; i--; ) {
237+ out = ["Cons", arr[i], out];
238+ }
239+ return out;
240+ }
241+ }
242+ }
243+ function zip(listA) {
244+ return function(listB) {
245+ if (listA[0] === "Nil" || listB[0] === "Nil") { return listA; }
246+ if (listA[0] !== "Cons" || listB[0] !== "Cons") { throwError(); }
247+ var arr = [];
248+ while (listA[0] === "Cons" && listB[0] === "Cons") {
249+ arr.push(["Tuple2", listA[1], listB[1]]);
250+ listA = listA[2];
251+ listB = listB[2];
252+ }
253+ var out = ["Nil"];
254+ for (var i = arr.length; i--; ) {
255+ out = ["Cons", arr[i], out];
256+ }
257+ return out;
258+ }
259+ }
260+ function unzip(pairs_112) {
261+ return function() {
262+ var v = pairs_112;
263+ var c = [function(v) {
264+ if("Nil" !== v[0]) {
265+ return undefined
266+ }else {
267+ return["Tuple2", ["Nil"], ["Nil"]]
268+ }
269+ }, function(v) {
270+ if("Cons" !== v[0]) {
271+ return undefined
272+ }else {
273+ var p_113 = v[1];
274+ var ps_114 = v[2];
275+ return function(v) {
276+ if("Tuple2" !== v[0]) {
277+ return undefined
278+ }else {
279+ if("Tuple2" !== v[1][0]) {
280+ return undefined
281+ }else {
282+ var x_115 = v[1][1];
283+ var y_116 = v[1][2];
284+ if("Tuple2" !== v[2][0]) {
285+ return undefined
286+ }else {
287+ var xs_117 = v[2][1];
288+ var ys_118 = v[2][2];
289+ return["Tuple2", ["Cons", x_115, xs_117], ["Cons", y_116, ys_118]]
290+ }
291+ }
292+ }
293+ }(["Tuple2", p_113, unzip(ps_114)])
294+ }
295+ }];
296+ for(var i = c.length;i--;) {
297+ var r = c[i](v);
298+ if(r !== undefined) {
299+ return r
300+ }
301+ }
302+ }()
303+ }
304+ function intersperse(sep_119) {
305+ return function(xs_120) {
306+ return function() {
307+ var v = xs_120;
308+ var c = [function(v) {
309+ if("Nil" !== v[0]) {
310+ return undefined
311+ }else {
312+ return["Nil"]
313+ }
314+ }, function(v) {
315+ if("Cons" !== v[0]) {
316+ return undefined
317+ }else {
318+ var a_124 = v[1];
319+ if("Nil" !== v[2][0]) {
320+ return undefined
321+ }else {
322+ return["Cons", a_124, ["Nil"]]
323+ }
324+ }
325+ }, function(v) {
326+ if("Cons" !== v[0]) {
327+ return undefined
328+ }else {
329+ var a_121 = v[1];
330+ if("Cons" !== v[2][0]) {
331+ return undefined
332+ }else {
333+ var b_122 = v[2][1];
334+ var cs_123 = v[2][2];
335+ return["Cons", a_121, ["Cons", sep_119, intersperse(sep_119)(["Cons", b_122, cs_123])]]
336+ }
337+ }
338+ }];
339+ for(var i = c.length;i--;) {
340+ var r = c[i](v);
341+ if(r !== undefined) {
342+ return r
343+ }
344+ }
345+ }()
346+ }
347+ }
348+ function intercalate(sep_125) {
349+ return function(xs_126) {
350+ return function() {
351+ var v = xs_126;
352+ var c = [function(v) {
353+ if("Nil" !== v[0]) {
354+ return undefined
355+ }else {
356+ return["Nil"]
357+ }
358+ }, function(v) {
359+ if("Cons" !== v[0]) {
360+ return undefined
361+ }else {
362+ var a_130 = v[1];
363+ if("Nil" !== v[2][0]) {
364+ return undefined
365+ }else {
366+ return a_130
367+ }
368+ }
369+ }, function(v) {
370+ if("Cons" !== v[0]) {
371+ return undefined
372+ }else {
373+ var a_127 = v[1];
374+ if("Cons" !== v[2][0]) {
375+ return undefined
376+ }else {
377+ var b_128 = v[2][1];
378+ var cs_129 = v[2][2];
379+ return Value.append(a_127, Value.append(sep_125, intercalate(sep_125)(["Cons", b_128, cs_129])))
380+ }
381+ }
382+ }];
383+ for(var i = c.length;i--;) {
384+ var r = c[i](v);
385+ if(r !== undefined) {
386+ return r
387+ }
388+ }
389+ }()
390+ }
391+ }
392+ function sort(xs) {
393+ if (xs[0] === "Nil") { return xs; }
394+ if (xs[0] !== "Cons") { throwError(); }
395+ var arr = [];
396+ while (xs[0] === "Cons") {
397+ arr.push(xs[1]);
398+ xs = xs[2];
399+ }
400+ arr.sort(function(a,b) { return a - b});
401+ var out = ["Nil"];
402+ for (var i = arr.length; i--; ) {
403+ out = [ "Cons", arr[i], out ];
404+ }
405+ return out;
406+ }
407+ return {head:head,
408+ tail:tail,
409+ map:map,
410+ foldl:foldl,
411+ foldr:foldr,
412+ foldl1:foldl1,
413+ foldr1:foldr1,
414+ scanl:scanl,
415+ scanl1:scanl1,
416+ filter:filter,
417+ length:length,
418+ reverse:reverse,
419+ concat:concat,
420+ concatMap:concatMap,
421+ and:and,
422+ or:or,
423+ forall:forall,
424+ exists:exists,
425+ sum:sum,
426+ product:product,
427+ maximum:maximum,
428+ minimum:minimum,
429+ partition:partition,
430+ zipWith:zipWith,
431+ zip:zip,
432+ unzip:unzip,
433+ intersperse:intersperse,
434+ intercalate:intercalate,
435+ sort:sort};
436+}();
core-js/String.jsnew file+22
@@ -0,0 +1,22 @@
1+var String = function() {
2+ var properEscape = function(str) {
3+ str.replace('"', "&#34;");
4+ str.replace("&", "&#38;");
5+ str.replace("'", "&#39;");
6+ str.replace("<", "&#60;");
7+ str.replace(">", "&#62;");
8+ return str;
9+ };
10+
11+ var toText = function(elmList) {
12+ var a = [];
13+ while (elmList[0] === "Cons") {
14+ a.push(elmList[1]);
15+ elmList = elmList[2];
16+ }
17+ return String.properEscape(a.join(''));
18+ };
19+
20+ return {toText : toText,
21+ properEscape : properEscape };
22+}();
core-js/Text.jsnew file+52
@@ -0,0 +1,52 @@
1+
2+var Text = function() {
3+ var fromString = function(elmList) {
4+ var a = [];
5+ while (elmList[0] === "Cons") {
6+ a.push(elmList[1]);
7+ elmList = elmList[2];
8+ }
9+ return String.properEscape(a.join(''));
10+ };
11+
12+ var addTag = function(tag) { return function(text) {
13+ return '<' + tag + '>' + text + '</' + tag + '>';
14+ };
15+ };
16+ var addStyle = function(style, value) { return function(text) {
17+ return "<span style='" + style + ":" + value + "'>" + text + "</span>";
18+ };
19+ };
20+
21+ var typeface = function(name) { return addStyle('font-family', name); };
22+ var size = function(px) {
23+ return addStyle('font-size', px + 'px');
24+ };
25+ var header = addTag('h1');
26+ var height = function(h) { return addStyle('font-size', h+'em'); }
27+ var italic = addStyle('font-style', 'italic');
28+ var bold = addTag('b');
29+ var color = function(c) {
30+ return addStyle('color', Color.Internal.extract(c));
31+ };
32+ var underline = addStyle('text-decoration', 'underline');
33+ var overline = addStyle('text-decoration', 'overline');
34+ var strikeThrough = addStyle('text-decoration', 'line-through');
35+ var link = function(href) { return function(text) {
36+ return "<a href='" + fromString(href) + "'>" + text + "</a>";
37+ };
38+ };
39+
40+ return {fromString : fromString,
41+ toText: fromString,
42+ header : header,
43+ height : height,
44+ italic : italic,
45+ bold : bold,
46+ underline : underline,
47+ overline : overline,
48+ strikeThrough : strikeThrough,
49+ monospace : typeface('monospace'),
50+ color : color,
51+ link : link };
52+}();
core-js/Value.jsnew file+75
@@ -0,0 +1,75 @@
1+
2+var Value = function(){
3+ var Tuple = function() {
4+ var len = arguments.length;
5+ var arr = new Array(len+1);
6+ arr[0] = "Tuple" + arguments.length;
7+ for (var i = len; i--; ) {
8+ arr[i+1] = arguments[i];
9+ }
10+ return arr;
11+ };
12+
13+ var toString = function(v) {
14+ if (typeof v === "boolean") {
15+ return v ? "True" : "False";
16+ } else if (typeof v === "number") {
17+ return v+"";
18+ } else if (v[0]) {
19+ if (v[0].substring(0,5) === "Tuple") {
20+ var output = "";
21+ for (var i = v.length; --i; ) {
22+ output = "," + toString(v[i]) + output;
23+ }
24+ if (output[0] === ",") output = output.substring(1);
25+ return "("+output+")";
26+ } else if (v[0] === "Cons") {
27+ var start = (typeof v[1] === "string") ? '"' : "[";
28+ var end = (typeof v[1] === "string") ? '"' : "]";
29+ var div = (typeof v[1] === "string") ? "" : ",";
30+ var output = start + toString(v[1]);
31+ v = v[2];
32+ while (true) {
33+ if (v[0] === "Cons") {
34+ output += div + toString(v[1]);
35+ v = v[2];
36+ } else {
37+ return output + end;
38+ }
39+ }
40+ } else if (v[0] === "Nil") {
41+ return "[]";
42+ } else {
43+ var output = "";
44+ for (var i = v.length; --i; ) {
45+ output = " " + toString(v[i]) + output
46+ }
47+ output = v[0] + output;
48+ return (v.length > 1) ? "(" + output + ")" : output;
49+ }
50+ }
51+ return v+"";
52+ };
53+ var show = function(v) {
54+ return Text.monospace(String.properEscape(toString(v)));
55+ };
56+ var append = function(xs,ys) {
57+ if (typeof xs === "string" && typeof ys === "string") {
58+ return xs.concat(ys);
59+ }
60+ if (xs[0] === "Nil") {
61+ return ys;
62+ }
63+ var root = ["Cons", xs[1], ["Nil"]];
64+ var curr = root;
65+ xs = xs[2];
66+ while (xs[0]==="Cons") {
67+ curr[2] = ["Cons", xs[1], ["Nil"]];
68+ xs = xs[2];
69+ curr = curr[2];
70+ }
71+ curr[2] = ys;
72+ return root;
73+ };
74+ return {show:show, Tuple:Tuple, append:append};
75+}();
core-js/collage/Color.jsnew file+34
@@ -0,0 +1,34 @@
1+
2+var Color = function() {
3+
4+ var create = function(r,g,b,a) {
5+ return { r: Math.round(255*r),
6+ g: Math.round(255*g),
7+ b: Math.round(255*b),
8+ a: a };
9+ };
10+
11+ var extract = function(c) {
12+ if (c.a === 1) {
13+ return 'rgb(' + c.r + ',' + c.g + ',' + c.b + ')';
14+ }
15+ return 'rgba(' + c.r + ',' + c.g + ',' + c.b + ',' + c.a + ')';
16+ };
17+
18+ var rgba = function(r) { return function(g) { return function(b) {
19+ return function(a) { return create(r,g,b,a); }; }; };
20+ };
21+
22+ var rgb = function(r) { return function(g) { return function(b) {
23+ return create(r,g,b,1); }; };
24+ };
25+ return {black: create(0,0,0,1),
26+ white: create(1,1,1,1),
27+ red : create(1,0,0,1),
28+ green: create(0,1,0,1),
29+ blue : create(0,0,1,1),
30+ rgba : rgba,
31+ rgb : rgb,
32+ Internal : { extract:extract }
33+ };
34+}();
core-js/collage/Form.jsnew file+33
@@ -0,0 +1,33 @@
1+
2+var Form = function() {
3+ var move = function(x) { return function(y) { return function(form) {
4+ var t = form[1];
5+ return [form[0], [[x + t[0][0], y + t[0][1]], t[1], t[2]]];
6+ };
7+ };
8+ };
9+ var rotate = function(theta) { return function(form) {
10+ var t = form[1];
11+ return [form[0], [t[0], t[1] + 2* Math.PI*theta, t[2]]];
12+ };
13+ };
14+ var scale = function(s) { return function(form) {
15+ var t = form[1];
16+ return [form[0], [t[0], t[1], t[2] * s]];
17+ };
18+ };
19+ var create = function(howToDraw, center) {
20+ return [howToDraw, Transforms.create(center, 0, 1)];
21+ };
22+ var draw = function(form) {
23+ ctx.save();
24+ var trans = form[1];
25+ ctx.translate(trans[0][0], trans[0][1]);
26+ ctx.rotate(trans[1]);
27+ ctx.scale(trans[2], trans[2]);
28+ form[0](ctx);
29+ ctx.restore();
30+ return ctx;
31+ };
32+ return {create:create, move:move, rotate:rotate, scale:scale, draw:draw};
33+}();
core-js/collage/Image.jsnew file+9
@@ -0,0 +1,9 @@
1+
2+var Image = function() {
3+ var image = function(src) {
4+ var img = new Image(src);
5+ img.onload = function() {
6+
7+ };
8+ };
9+}();
core-js/collage/Line.jsnew file+103
@@ -0,0 +1,103 @@
1+
2+var Line = function() {
3+
4+ var pair = function(a,b) { return [a,b]; };
5+
6+ var create = function(center, ps, theta, s) {
7+ return { center: center, points: ps, theta: theta, scale: s };
8+ };
9+
10+
11+ //// Construction ////
12+
13+ var line = function(ps) {
14+ var parr = [];
15+ while (ps[0] === "Cons") {
16+ parr.push(pair(ps[1][1], ps[1][2]));
17+ ps = ps[2];
18+ }
19+ return create(pair(0,0), parr, 0, 1);
20+ };
21+
22+ //// Atomize ////
23+
24+ var solid = function(color) { return function(line) { return function(ctx) {
25+ ctx.save();
26+ ctx.beginPath();
27+ ctx.translate(line.center[0], line.center[1]);
28+ ctx.rotate(line.theta);
29+ ctx.scale(line.scale, line.scale);
30+ var points = line.points;
31+ var i = points.length;
32+ ctx.moveTo(points[i-1][0], points[i-1][1]);
33+ while (i--) {
34+ ctx.lineTo(points[i][0], points[i][1]);
35+ }
36+ ctx.strokeStyle = Color.Internal.extract(color);
37+ ctx.stroke();
38+ ctx.restore();
39+ return ctx;
40+ };
41+ };
42+ };
43+
44+ var customLine = function(pattern) {
45+ return function(color) { return function(line) {
46+ if (typeof pattern[0] === "string") {
47+ var temp = [];
48+ while (pattern[0] === "Cons") {
49+ temp.push(pattern[1]);
50+ pattern = pattern[2];
51+ }
52+ pattern = temp;
53+ }
54+ if (pattern.length === 0) { pattern = [8,4]; }
55+ return function(ctx) {
56+ ctx.save();
57+ ctx.beginPath();
58+ ctx.translate(line.center[0], line.center[1]);
59+ ctx.rotate(line.theta);
60+ ctx.scale(line.scale, line.scale);
61+ customLineHelp(ctx, pattern, line.points);
62+ ctx.strokeStyle = Color.Internal.extract(color);
63+ ctx.stroke();
64+ ctx.restore();
65+ return ctx;
66+ };
67+ };
68+ };
69+ };
70+ var customLineHelp = function(ctx, pattern, points) {
71+ var i = points.length - 1;
72+ var x0 = points[i][0], y0 = points[i][1];
73+ var x1=0, y1=0, dx=0, dy=0, remaining=0, nx=0, ny=0;
74+ var pindex = 0, plen = pattern.length;
75+ var draw = true, segmentLength = pattern[0];
76+ ctx.moveTo(x0,y0);
77+ while (i--) {
78+ x1 = points[i][0]; y1 = points[i][1];
79+ dx = x1 - x0; dy = y1 - y0;
80+ remaining = Math.sqrt(dx * dx + dy * dy);
81+ while (segmentLength <= remaining) {
82+ x0 += dx * segmentLength / remaining;
83+ y0 += dy * segmentLength / remaining;
84+ ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
85+ // update starting position
86+ dx = x1 - x0; dy = y1 - y0;
87+ remaining = Math.sqrt(dx * dx + dy * dy);
88+ // update pattern
89+ draw = !draw;
90+ pindex = (pindex + 1) % plen;
91+ segmentLength = pattern[pindex];
92+ }
93+ if (remaining > 0) {
94+ ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
95+ segmentLength -= remaining;
96+ }
97+ x0 = x1; y0 = y1;
98+ }
99+ };
100+
101+ return {line:line, customLine:customLine, solid:solid,
102+ dashed: customLine([8,4]), dotted: customLine([3,3]) };
103+}();
core-js/collage/Shape.jsnew file+110
@@ -0,0 +1,110 @@
1+
2+var Shape = function() {
3+
4+ var create = function(center, ps, theta, s) {
5+ return { center: center, points: ps, theta: theta, scale: s };
6+ };
7+
8+ //// Construction ////
9+
10+ var polygon = function(ps) { return function(center) {
11+ var parr = [];
12+ while (ps[0] === "Cons") {
13+ parr.push([ps[1][1], ps[1][2]]);
14+ ps = ps[2];
15+ }
16+ center = [center[1], center[2]];
17+ return create(center, parr, 0, 1);
18+ };
19+};
20+ var ngon = function(n) { return function(r) { return function(center) {
21+ var ps = [];
22+ for (var i = n; i--;) {
23+ ps.push([r * Math.cos(Math.PI * 2 * i/n),
24+ r * Math.sin(Math.PI * 2 * i/n)]);
25+ }
26+ center = [center[1], center[2]];
27+ return create(center, ps, 0, 1);
28+ };
29+ };
30+};
31+ var rect = function(w) { return function(h) { return function(center) {
32+ var ps = [[- w/2, - h/2],
33+ [ w/2, - h/2],
34+ [ w/2, h/2],
35+ [- w/2, h/2]];
36+ center = [center[1], center[2]];
37+ return create(center, ps, 0, 1);
38+ };
39+ };
40+ };
41+ var oval = function(w) { return function(h) { return function(center) {
42+ var ps = [];
43+ for (var theta = 2 * Math.PI; theta > 0; theta -= Math.PI /50) {
44+ ps.push([w/2 * Math.cos(theta), h/2 * Math.sin(theta)]);
45+ }
46+ center = [center[1], center[2]];
47+ return create(center, ps, 0, 1);
48+ };
49+ };
50+ };
51+
52+//// Transforms ////
53+
54+ var move = function(x) { return function(y) { return function(shape) {
55+ var newCenter = [x + shape.center[0],y + shape.center[1]];
56+ return create(newCenter, shape.points, shape.theta, shape.scale);
57+ };
58+ };
59+ };
60+ var rotate = function(theta) { return function(shape) {
61+ var newTheta = shape.theta + 2 * Math.PI * theta;
62+ return create(shape.center, shape.points, newTheta, shape.scale);
63+ };
64+ };
65+ var scale = function(s) { return function(shape) {
66+ return create(shape.center, shape.points, shape.theta, shape.scale * s);
67+ };
68+ };
69+
70+
71+ //// Atomize ////
72+
73+ var draw = function(fill) {
74+ return function(color) { return function(shape) { return function(ctx) {
75+ ctx.save();
76+ ctx.translate(shape.center[0], shape.center[1]);
77+ ctx.rotate(shape.theta);
78+ ctx.scale(shape.scale, shape.scale);
79+ ctx.beginPath();
80+ var points = shape.points;
81+ ctx.moveTo(points[0][0], points[0][1]);
82+ for (var i = points.length; i--; ) {
83+ ctx.lineTo(points[i][0], points[i][1]);
84+ }
85+ ctx.closePath();
86+ if (fill) {
87+ ctx.fillStyle = Color.Internal.extract(color);
88+ ctx.fill();
89+ } else {
90+ ctx.strokeStyle = Color.Internal.extract(color);
91+ ctx.stroke();
92+ }
93+ ctx.restore();
94+ return ctx;
95+ };
96+ };
97+ };
98+ };
99+
100+ var customOutline = function(p) {
101+ return function(c) { return function(shape) {
102+ shape.points.push(shape.points[0]);
103+ return Line.customLine(p)(c)(shape);
104+ };
105+ };
106+ };
107+ return {polygon:polygon, ngon:ngon, rect:rect, oval:oval,
108+ move:move, rotate:rotate, scale:scale,
109+ filled:draw(true), outlined:draw(false), customOutline:customOutline };
110+}();
core-js/runtime/Dispatcher.jsnew file+146
@@ -0,0 +1,146 @@
1+
2+var Elm = function() {
3+ var input = function(base) {
4+ this.id = Guid.guid();
5+ this.value = base;
6+ this.step = function(eid,v) {
7+ var changed = eid === this.id;
8+ if (changed) { this.value = v; }
9+ return changed;
10+ };
11+ };
12+ var lift = function(func,args) {
13+ this.id = Guid.guid();
14+ this.value = null;
15+
16+ args.reverse();
17+ this.recalc = function() {
18+ var f = func;
19+ for (var i = args.length; i--; ) {
20+ f = f(args[i].value);
21+ }
22+ this.value = f;
23+ };
24+ this.recalc();
25+
26+ this.step = function(id,v) {
27+ if (this.hasOwnProperty(id)) return false;
28+ var changed = false;
29+ for (var i = args.length; i--; ) {
30+ changed = changed || args[i].step(id,v);
31+ }
32+ changed ? (this.recalc()) : (this[id] = true);
33+ return changed;
34+ };
35+ };
36+ var fold = function(func,base,input) {
37+ this.id = Guid.guid();
38+ this.value = base;
39+ this.step = function(id,v) {
40+ if (this.hasOwnProperty(id)) return false;
41+ var changed = input.step(id,v);
42+ if (changed) { this.value = func(input.value)(this.value); }
43+ else { this[id] = true; }
44+ return changed;
45+ };
46+ };
47+ return {Input: function(x) {return new input(x);},
48+ Lift: function(f,xs){return new lift(f,xs);},
49+ Fold: function(f,b,x){return new fold(f,b,x);}
50+ };
51+}();
52+
53+var Dispatcher = function() {
54+ var program = null;
55+ var update = function(context, newNode, oldNode) {
56+ if (oldNode.style && newNode.style) {
57+ oldNode.style.width = newNode.style.width;
58+ oldNode.style.height = newNode.style.height;
59+ }
60+ if (newNode.hasOwnProperty('isElmLeaf') &&
61+ oldNode.hasOwnProperty('isElmLeaf')) {
62+ newNode.id = oldNode.id;
63+ if (!newNode.isEqualNode(oldNode)) {
64+ context.replaceChild(newNode, oldNode);
65+ }
66+ return;
67+ }
68+ if (newNode.nodeName === "CANVAS") {
69+ context.replaceChild(newNode, oldNode);
70+ return;
71+ }
72+ var nlist = newNode.childNodes;
73+ var olist = oldNode.childNodes;
74+ if (nlist.length !== olist.length) {
75+ context.replaceChild(newNode, oldNode);
76+ return;
77+ }
78+ for (var i = nlist.length; i--; ) {
79+ update(oldNode, nlist[i], olist[i]);
80+ }
81+ };
82+
83+ var correctSize = function(e) {
84+ var kids = e.childNodes;
85+ var len = kids.length;
86+ if (e.hasOwnProperty('isElmLeaf')) {
87+ var w = e.style.width === "" ?
88+ 0 : e.style.width.slice(0,-2) - 0;
89+ var h = e.style.height === "" ?
90+ 0 : e.style.height.slice(0,-2) - 0;
91+ return [w, h];
92+ }
93+ if (len === 1) {
94+ var dim = correctSize(kids[0]);
95+ if (e.style.width !== "") { dim[0] = e.style.width.slice(0,-2) - 0; }
96+ if (e.style.height !== "") { dim[1] = e.style.height.slice(0,-2) - 0; }
97+ if (dim[0] !== 0) { e.style.width = dim[0] + "px"; }
98+ if (dim[1] !== 0) { e.style.height = dim[1] + "px"; }
99+ return dim;
100+ }
101+ var wmax = 0, hmax = 0, wsum = 0, hsum = 0;
102+ var hasWidth = true, hasHeight = true, dim = null;
103+ while (len--) {
104+ dim = correctSize(kids[len]);
105+ wmax = Math.max(wmax, dim[0]);
106+ hmax = Math.max(hmax, dim[1]);
107+ wsum += dim[0];
108+ hsum += dim[1];
109+ hasWidth = hasWidth && dim[0] > 0;
110+ hasHeight = hasHeight && dim[1] > 0;
111+ }
112+ var w = wmax, h = hmax, dir = e.elmFlowDirection;
113+ if (dir === "X") { w = hasWidth ? wsum : 0; }
114+ if (dir === "Y") { h = hasHeight ? hsum : 0; }
115+ if (w > 0) e.style.width = w + "px";
116+ if (h > 0) e.style.height = h + "px";
117+ return [w,h];
118+ };
119+
120+ var initialize = function() {
121+ /*try {*/ program = main(); //}
122+ //catch (e) { program = text("An Error Occured: Better Messages to come."); }
123+ if (!program.hasOwnProperty('step')) {
124+ program = Elm.Input(program);
125+ }
126+ var content = document.getElementById('content');
127+ content.appendChild(program.value);
128+ correctSize(content);
129+ var w = document.getElementById('widthChecker').offsetWidth;
130+ if (w !== window.innerWidth) {
131+ Dispatcher.notify(Window.dimensions.id, Value.Tuple(w, window.innerHeight));
132+ }
133+ };
134+ var adjust = function() {
135+ var content = document.getElementById('content');
136+ correctSize(content);
137+ }
138+ var notify = function(id, v) {
139+ if (program.step(id,v)) {
140+ var content = document.getElementById('content');
141+ update(content, program.value, content.children[0]);
142+ correctSize(content);
143+ }
144+ };
145+ return {initialize:initialize, notify:notify, adjust:adjust};
146+}();
core-js/runtime/Signal.jsnew file+207
@@ -0,0 +1,207 @@
1+
2+var Signal = function() {
3+ var addListener = function() {
4+ if(document.addEventListener) {
5+ return function(element, event, handler) {
6+ element.addEventListener(event, handler, false);
7+ };
8+ }
9+ else {
10+ return function(element, event, handler) {
11+ element.attachEvent('on' + event, handler);
12+ };
13+ }
14+ }();
15+
16+ var Mouse = function() {
17+ var position = Elm.Input(Value.Tuple(0,0));
18+ var isDown = Elm.Input(false);
19+ var isClicked = Elm.Input(false);
20+
21+ function getXY(e) {
22+ var posx = 0;
23+ var posy = 0;
24+ if (!e) var e = window.event;
25+ if (e.pageX || e.pageY) {
26+ posx = e.pageX;
27+ posy = e.pageY;
28+ } else if (e.clientX || e.clientY) {
29+ posx = e.clientX + document.body.scrollLeft +
30+ document.documentElement.scrollLeft;
31+ posy = e.clientY + document.body.scrollTop +
32+ document.documentElement.scrollTop;
33+ }
34+ return Value.Tuple(posx, posy);
35+ }
36+
37+ addListener(document, 'click', function(e) {
38+ Dispatcher.notify(isClicked.id, true);
39+ Dispatcher.notify(isClicked.id, false);
40+ });
41+ addListener(document, 'mousedown', function(e) {
42+ Dispatcher.notify(isDown.id, true); });
43+ addListener(document, 'mouseup', function(e) {
44+ Dispatcher.notify(isDown.id, false); });
45+ addListener(document, 'mousemove', function(e) {
46+ Dispatcher.notify(position.id, getXY(e)); });
47+ return {position: position,
48+ x: Elm.Lift(function(p){return p[1];},[position]),
49+ y: Elm.Lift(function(p){return p[2];},[position]),
50+ isClicked: isClicked,
51+ isDown: isDown
52+ };
53+ }();
54+
55+ var Time = function() {
56+ var every = function(t) {
57+ t *= 1000;
58+ var clock = Elm.Input(0);
59+ var time = 0;
60+ setInterval(function() {
61+ time += t;
62+ Dispatcher.notify(clock.id, time/1000);
63+ }, t);
64+ return clock;
65+ };
66+ var after = function(t) {
67+ t *= 1000;
68+ var thread = Elm.Input(false);
69+ setTimeout(function() { Dispatcher.notify(thread.id, true); }, t);
70+ return thread;
71+ };
72+ var before = function(t) {
73+ t *= 1000;
74+ var thread = Elm.Input(true);
75+ setTimeout(function() { Dispatcher.notify(thread.id, false); }, t);
76+ return thread;
77+ };
78+ return {every:every,after:after,before:before};
79+ }();
80+
81+ var Window = function() {
82+ var dimensions = Elm.Input(Value.Tuple(window.innerWidth,window.innerHeight));
83+ addListener(window, 'resize', function(e) {
84+ var w = document.getElementById('widthChecker').offsetWidth;
85+ Dispatcher.notify(dimensions.id, Value.Tuple(w, window.innerHeight));
86+ });
87+ return {dimensions:dimensions,
88+ width : Elm.Lift(function(p){return p[1];},[dimensions]),
89+ height: Elm.Lift(function(p){return p[2];},[dimensions]) };
90+ }();
91+
92+ var HTTP = function() {
93+ var fetch = function(how) { return function(url) {
94+ var thread = Elm.Input("Requesting Data...");
95+ if (window.XMLHttpRequest) {
96+ request = new XMLHttpRequest();
97+ } else if (window.ActiveXObject) {
98+ request = new ActiveXObject("Microsoft.XMLHTTP");
99+ }
100+ request.onreadystatechange = function(e) {
101+ var result = "";
102+ if (request.readyState === 4) {
103+ result = request.status === 200 ? request.responseText
104+ : request.statusText;
105+ } else {
106+ result = 'Request Failed';
107+ }
108+ Dispatcher.notify(thread.id, result);
109+ };
110+ request.open(how, String.toText(url), true);
111+ request.send(null);
112+ return thread;
113+ };
114+ };
115+ return { get : fetch("GET"), post : fetch("POST") };
116+ }();
117+ var Random = function() {
118+ var inRange = function(min) { return function(max) {
119+ return Elm.Input(Math.floor(Math.random() * (max-min+1)) + min);
120+ };
121+ };
122+ var randomize = function(min) { return function(max) { return function(signal) {
123+ return Elm.Lift(function(x) { return Math.floor(Math.random() * (max-min+1)) + min;},[signal]);
124+ };
125+ };
126+ };
127+ return { inRange:inRange, randomize:randomize };
128+ }();
129+ var Input = function() {
130+ function toElmString(str) {
131+ var out = ["Nil"];
132+ for (var i = str.length; i--; ) {
133+ out = ["Cons", str[i], out];
134+ }
135+ return out;
136+ }
137+ var newTextInput = function(elem, ghostText) {
138+ elem.isElmLeaf = true;
139+ var str = Elm.Input(["Nil"]);
140+ addListener(elem, 'keyup', function(e) {
141+ Dispatcher.notify(str.id, toElmString(elem.value));
142+ elem.focus();
143+ });
144+ return Value.Tuple(elem, str);
145+ };
146+ var newElement = function(name) {
147+ var e = document.createElement(name);
148+ e.id = Guid.guid();
149+ return e;
150+ };
151+ var textArea = function(cols) { return function(rows) {
152+ var textarea = newElement('textarea');
153+ textarea.rows = rows;
154+ textarea.cols = cols;
155+ return newTextInput(textarea, "");
156+ };
157+ };
158+ var textField = function(ghostText) {
159+ var field = newElement('input');
160+ field.type = 'text';
161+ return newTextInput(field, ghostText);
162+ };
163+ var password = function(ghostText) {
164+ var field = newElement('input');
165+ field.type = 'password';
166+ return newTextInput(field, ghostText);
167+ };
168+ var checkbox = function(checked) {
169+ var box = newElement('input');
170+ box.type = 'checkbox';
171+ box.checked = checked;
172+ var status = Elm.Input(checked);
173+ console.log(checked, box);
174+ addListener(box, 'change', function(e) {
175+ Dispatcher.notify(status.id, box.checked);
176+ });
177+ return Value.Tuple(box, status);
178+ };
179+ var dropDown = function(options) {
180+ var slct = newElement('select');
181+ var opts = [];
182+ while (options[0] === "Cons") {
183+ var opt = newElement('option');
184+ var str = Text.toText(options[1][1]);
185+ opt.value = str;
186+ opt.innerHTML = str;
187+ slct.appendChild(opt);
188+ opts.push(options[1][2]);
189+ options = options[2];
190+ }
191+ var status = Elm.Input(opts[0]);
192+ addListener(slct, 'change', function(e) {
193+ Dispatcher.notify(status.id, opts[slct.selectedIndex]);
194+ });
195+ return Value.Tuple(slct, status);
196+ };
197+ var stringDropDown = function(opts) {
198+ return dropDown(List.map (function(x) {return Value.Tuple(x,x);}) (opts));
199+ };
200+ return {textArea:textArea, textField:textField,
201+ password:password, checkbox:checkbox,
202+ dropDown:dropDown, stringDropDown:stringDropDown};
203+ }();
204+
205+ return {Mouse:Mouse, Time:Time, Window:Window,
206+ HTTP:HTTP, Random:Random, Input:Input };
207+}();