2var Signal = function() {
3 function toElmString(str) {
5 for (var i = str.length; i--; ) {
6 out = ["Cons", str[i], out];
10 var addListener = function() {
11 if(document.addEventListener) {
12 return function(element, event, handler) {
13 element.addEventListener(event, handler, false);
17 return function(element, event, handler) {
18 element.attachEvent('on' + event, handler);
23 var Mouse = function() {
24 var position = Elm.Input(Value.Tuple(0,0));
25 var isDown = Elm.Input(false);
26 var isClicked = Elm.Input(false);
31 if (!e) var e = window.event;
32 if (e.pageX || e.pageY) {
35 } else if (e.clientX || e.clientY) {
36 posx = e.clientX + document.body.scrollLeft +
37 document.documentElement.scrollLeft;
38 posy = e.clientY + document.body.scrollTop +
39 document.documentElement.scrollTop;
41 return Value.Tuple(posx, posy);
44 addListener(document, 'click', function(e) {
45 Dispatcher.notify(isClicked.id, true);
46 Dispatcher.notify(isClicked.id, false);
48 addListener(document, 'mousedown', function(e) {
49 Dispatcher.notify(isDown.id, true); });
50 addListener(document, 'mouseup', function(e) {
51 Dispatcher.notify(isDown.id, false); });
52 addListener(document, 'mousemove', function(e) {
53 Dispatcher.notify(position.id, getXY(e)); });
54 var clickedOn = function(elem) {
55 var click = Elm.Input(false);
56 addListener(elem, 'click', function(e) {
57 Dispatcher.notify(click.id, true);
58 Dispatcher.notify(click.id, false);
60 return Value.Tuple(elem, click);
62 return {position: position,
63 x: Elm.Lift(function(p){return p[1];},[position]),
64 y: Elm.Lift(function(p){return p[2];},[position]),
71 var Time = function() {
72 var every = function(t) {
74 var clock = Elm.Input(0);
76 setInterval(function() {
78 Dispatcher.notify(clock.id, time/1000);
82 var after = function(t) {
84 var thread = Elm.Input(false);
85 setTimeout(function() { Dispatcher.notify(thread.id, true); }, t);
88 var before = function(t) {
90 var thread = Elm.Input(true);
91 setTimeout(function() { Dispatcher.notify(thread.id, false); }, t);
94 return {every:every,after:after,before:before};
97 var Window = function() {
98 var dimensions = Elm.Input(Value.Tuple(window.innerWidth,window.innerHeight));
99 addListener(window, 'resize', function(e) {
100 var w = document.getElementById('widthChecker').offsetWidth;
101 Dispatcher.notify(dimensions.id, Value.Tuple(w, window.innerHeight));
103 return {dimensions:dimensions,
104 width : Elm.Lift(function(p){return p[1];},[dimensions]),
105 height: Elm.Lift(function(p){return p[2];},[dimensions]) };
108 var HTTP = function() {
109 var fetch = function(how) { return function(url) {
110 var thread = Elm.Input(["Waiting"]);
112 if (window.XMLHttpRequest) { request = new XMLHttpRequest(); }
113 else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
114 request.onreadystatechange = function(e) {
115 if (request.readyState === 4) {
116 Dispatcher.notify(thread.id,
117 request.status === 200
118 ? ["Success", toElmString(request.responseText)]
119 : ["Failure", request.status, toElmString(request.statusText)]);
122 request.open(how, String.toText(url), true);
127 var fetches = function(how) { return function(input) {
128 var output = Elm.Input(["Nothing"]);
129 var fetcher = Elm.Lift(update, [input]);
130 var combine = Elm.Lift(function(x) { return function(y) { return x; } }, [output,fetcher]);
131 function update(strOpt) {
132 if (strOpt[0] !== "Just") {
133 try { Dispatcher.notify(output.id, ["Nothing"]); } catch(e) {}
137 Dispatcher.notify(output.id, ["Just", ["Waiting"]]);
138 } catch(e) { output.value = ["Just", ["Waiting"]]; }
140 if (window.XMLHttpRequest) { request = new XMLHttpRequest(); }
141 else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
142 request.onreadystatechange = function(e) {
143 if (request.readyState === 4) {
144 Dispatcher.notify(output.id,
145 ["Just", request.status === 200
146 ? ["Success", toElmString(request.responseText)]
147 : ["Failure", request.status, toElmString(request.statusText)]]);
150 request.open(how, String.toText(strOpt[1]), true);
157 return {get : fetch("GET"), post : fetch("POST"),
158 gets : fetches("GET"), posts : fetches("POST") };
160 var Random = function() {
161 var inRange = function(min) { return function(max) {
162 return Elm.Input(Math.floor(Math.random() * (max-min+1)) + min);
165 var randomize = function(min) { return function(max) { return function(signal) {
166 return Elm.Lift(function(x) { return Math.floor(Math.random() * (max-min+1)) + min;},[signal]);
170 return { inRange:inRange, randomize:randomize };
172 var Input = function() {
173 var newTextInput = function(elem, ghostText) {
174 elem.isElmLeaf = true;
175 var str = Elm.Input(["Nil"]);
176 addListener(elem, 'keyup', function(e) {
177 Dispatcher.notify(str.id, toElmString(elem.value));
180 return Value.Tuple(elem, str);
182 var newElement = function(name) {
183 var e = document.createElement(name);
187 var textArea = function(cols) { return function(rows) {
188 var textarea = newElement('textarea');
189 textarea.rows = rows;
190 textarea.cols = cols;
191 return newTextInput(textarea, "");
194 var textField = function(ghostText) {
195 var field = newElement('input');
197 return newTextInput(field, ghostText);
199 var password = function(ghostText) {
200 var field = newElement('input');
201 field.type = 'password';
202 return newTextInput(field, ghostText);
204 var checkbox = function(checked) {
205 var box = newElement('input');
206 box.type = 'checkbox';
207 box.checked = checked;
208 var status = Elm.Input(checked);
209 addListener(box, 'change', function(e) {
210 Dispatcher.notify(status.id, box.checked);
212 return Value.Tuple(box, status);
214 var dropDown = function(options) {
215 var slct = newElement('select');
217 while (options[0] === "Cons") {
218 var opt = newElement('option');
219 var str = Text.toText(options[1][1]);
222 slct.appendChild(opt);
223 opts.push(options[1][2]);
224 options = options[2];
226 var status = Elm.Input(opts[0]);
227 addListener(slct, 'change', function(e) {
228 Dispatcher.notify(status.id, opts[slct.selectedIndex]);
230 return Value.Tuple(slct, status);
232 var stringDropDown = function(opts) {
233 return dropDown(List.map (function(x) {return Value.Tuple(x,x);}) (opts));
235 var button = function(name) {
236 var b = newElement('input');
238 b.value = Text.toText(name);
239 var press = Elm.Input(false);
240 addListener(b, 'click', function(e) {
241 Dispatcher.notify(press.id, true);
242 Dispatcher.notify(press.id, false);
244 return Value.Tuple(b,press);
246 return {textArea:textArea, textField:textField,
247 password:password, checkbox:checkbox,
248 dropDown:dropDown, stringDropDown:stringDropDown,
252 return {Mouse:Mouse, Time:Time, Window:Window,
253 HTTP:HTTP, Random:Random, Input:Input };
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