@@ -1,67 +1,67 @@
11Elm.Native.Mouse = {};
22Elm.Native.Mouse.make = function(elm) {
33
4− elm.Native = elm.Native || {};
5− elm.Native.Mouse = elm.Native.Mouse || {};
6− if (elm.Native.Mouse.values) return elm.Native.Mouse.values;
4+ elm.Native = elm.Native || {};
5+ elm.Native.Mouse = elm.Native.Mouse || {};
6+ if (elm.Native.Mouse.values) return elm.Native.Mouse.values;
77
8− var Signal = Elm.Signal.make(elm);
9− var Utils = Elm.Native.Utils.make(elm);
8+ var Signal = Elm.Signal.make(elm);
9+ var Utils = Elm.Native.Utils.make(elm);
1010
11− var position = Signal.constant(Utils.Tuple2(0,0));
12− position.defaultNumberOfKids = 2;
11+ var position = Signal.constant(Utils.Tuple2(0,0));
12+ position.defaultNumberOfKids = 2;
1313
14− // do not move x and y into Elm. 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 = A2( Signal.lift, function(p){return p._0}, position);
18− x.defaultNumberOfKids = 0;
19− var y = A2( Signal.lift, function(p){return p._1}, position);
20− y.defaultNumberOfKids = 0;
14+ // do not move x and y into Elm. 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 = A2( Signal.lift, function(p){return p._0}, position);
18+ x.defaultNumberOfKids = 0;
19+ var y = A2( Signal.lift, function(p){return p._1}, position);
20+ y.defaultNumberOfKids = 0;
2121
22− var isDown = Signal.constant(false);
23− var isClicked = Signal.constant(false);
24− var clicks = Signal.constant(Utils.Tuple0);
22+ var isDown = Signal.constant(false);
23+ var isClicked = Signal.constant(false);
24+ var clicks = Signal.constant(Utils.Tuple0);
2525
26− function getXY(e) {
27− var posx = 0;
28− var posy = 0;
29− if (!e) e = window.event;
30− if (e.pageX || e.pageY) {
31− posx = e.pageX;
32− posy = 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;
26+ function getXY(e) {
27+ var posx = 0;
28+ var posy = 0;
29+ if (!e) e = window.event;
30+ if (e.pageX || e.pageY) {
31+ posx = e.pageX;
32+ posy = 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;
38+ }
39+ return Utils.Tuple2(posx-elm.node.offsetX, posy-elm.node.offsetY);
3840 }
39− return Utils.Tuple2(posx-elm.node.offsetX, posy-elm.node.offsetY);
40− }
4141
42− var node = elm.display === ElmRuntime.Display.FULLSCREEN ? document : elm.node;
42+ var node = elm.display === ElmRuntime.Display.FULLSCREEN ? document : elm.node;
4343
44− elm.addListener([isClicked.id, clicks.id], node, 'click', function click() {
45− elm.notify(isClicked.id, true);
46− elm.notify(clicks.id, Utils.Tuple0);
47− elm.notify(isClicked.id, false);
48− });
49− elm.addListener([isDown.id], node, 'mousedown', function down() {
50− elm.notify(isDown.id, true);
51− });
52− elm.addListener([isDown.id], node, 'mouseup', function up() {
53− elm.notify(isDown.id, false);
54− });
55− elm.addListener([position.id], node, 'mousemove', function move(e) {
56− elm.notify(position.id, getXY(e));
57− });
44+ elm.addListener([isClicked.id, clicks.id], node, 'click', function click() {
45+ elm.notify(isClicked.id, true);
46+ elm.notify(clicks.id, Utils.Tuple0);
47+ elm.notify(isClicked.id, false);
48+ });
49+ elm.addListener([isDown.id], node, 'mousedown', function down() {
50+ elm.notify(isDown.id, true);
51+ });
52+ elm.addListener([isDown.id], node, 'mouseup', function up() {
53+ elm.notify(isDown.id, false);
54+ });
55+ elm.addListener([position.id], node, 'mousemove', function move(e) {
56+ elm.notify(position.id, getXY(e));
57+ });
5858
59− return elm.Native.Mouse.values = {
60− position: position,
61− x:x,
62− y:y,
63− isClicked: isClicked,
64− isDown: isDown,
65− clicks: clicks
66− };
59+ return elm.Native.Mouse.values = {
60+ position: position,
61+ x:x,
62+ y:y,
63+ isClicked: isClicked,
64+ isDown: isDown,
65+ clicks: clicks
66+ };
6767};