9 var Misc = Elm.Native.Misc;
11 var position = Elm.Signal.constant(Misc.Tuple(0,0));
12 position.defaultNumberOfKids = 2;
14 // do not get rid of x and y. By setting their default number
15 // of kids, it is possible to detatch the mouse listeners if
16 // they are not needed.
17 var x = Elm.Signal.lift(function(p){return p._0})(position);
18 x.defaultNumberOfKids = 0;
19 var y = Elm.Signal.lift(function(p){return p._1})(position);
20 y.defaultNumberOfKids = 0;
22 var isDown = Elm.Signal.constant(false);
23 var isClicked = Elm.Signal.constant(false);
24 var clicks = Elm.Signal.constant(Misc.Tuple());
29 if (!e) e = window.event;
30 if (e.pageX || e.pageY) {
33 } else if (e.clientX || e.clientY) {
34 posx = e.clientX + document.body.scrollLeft +
35 document.documentElement.scrollLeft;
36 posy = e.clientY + document.body.scrollTop +
37 document.documentElement.scrollTop;
39 return Misc.Tuple(posx, posy);
42 Misc.addListener(document, 'click', function(e) {
43 var hasListener1 = Dispatcher.notify(isClicked.id, true);
44 var hasListener2 = Dispatcher.notify(clicks.id, Misc.Tuple());
45 Dispatcher.notify(isClicked.id, false);
46 if (!hasListener1 && !hasListener2)
47 this.removeEventListener('click',arguments.callee,false);
49 Misc.addListener(document, 'mousedown', function(e) {
50 var hasListener = Dispatcher.notify(isDown.id, true);
52 this.removeEventListener('mousedown',arguments.callee,false);
54 Misc.addListener(document, 'mouseup', function(e) {
55 var hasListener = Dispatcher.notify(isDown.id, false);
57 this.removeEventListener('mouseup',arguments.callee,false);
59 Misc.addListener(document, 'mousemove', function(e) {
60 var hasListener = Dispatcher.notify(position.id, getXY(e));
62 this.removeEventListener('mousemove',arguments.callee,false);
65 var clickedOn = function(elem) {
66 var node = Render.render(elem);
67 var click = Elm.Signal.constant(false);
68 Misc.addListener(node, 'click', function(e) {
69 Dispatcher.notify(click.id, true);
70 Dispatcher.notify(click.id, false);
72 return Misc.Tuple(Misc.wrap(node), click);
74 Elm.Native.Mouse = {position: position,
80 isClickedOn: clickedOn};
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