2Elm.Native.Mouse = function(elm) {
4 elm.Native = elm.Native || {};
5 if (elm.Native.Mouse) return elm.Native.Mouse;
7 var Signal = Elm.Signal(elm);
8 var Utils = Elm.Native.Utils(elm);
10 var position = Signal.constant(Utils.Tuple2(0,0));
11 position.defaultNumberOfKids = 2;
13 // do not move x and y into Elm. By setting their default number
14 // of kids, it is possible to detatch the mouse listeners if
15 // they are not needed.
16 var x = A2( Signal.lift, function(p){return p._0}, position);
17 x.defaultNumberOfKids = 0;
18 var y = A2( Signal.lift, function(p){return p._1}, position);
19 y.defaultNumberOfKids = 0;
21 var isDown = Signal.constant(false);
22 var isClicked = Signal.constant(false);
23 var clicks = Signal.constant(Utils.Tuple0);
28 if (!e) e = window.event;
29 if (e.pageX || e.pageY) {
32 } else if (e.clientX || e.clientY) {
33 posx = e.clientX + document.body.scrollLeft +
34 document.documentElement.scrollLeft;
35 posy = e.clientY + document.body.scrollTop +
36 document.documentElement.scrollTop;
38 return Utils.Tuple2(posx-elm.node.offsetX, posy-elm.node.offsetY);
41 var node = elm.display === ElmRuntime.Display.FULLSCREEN ? document : elm.node;
43 elm.addListener([isClicked.id, clicks.id], node, 'click', function click() {
44 elm.notify(isClicked.id, true);
45 elm.notify(clicks.id, Utils.Tuple0);
46 elm.notify(isClicked.id, false);
48 elm.addListener([isDown.id], node, 'mousedown', function down() {
49 elm.notify(isDown.id, true);
51 elm.addListener([isDown.id], node, 'mouseup', function up() {
52 elm.notify(isDown.id, false);
54 elm.addListener([position.id], node, 'mousemove', function move(e) {
55 elm.notify(position.id, getXY(e));
58 return elm.Native.Mouse = {
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