@@ -1,44 +1,18 @@
1−/*! Mouse
2− !*/
31
4−Elm.Mouse = function() {
5− /*[Position]*/
6−
7− /** position : Signal (Int,Int)
8− The current mouse position.
9− **/
2+function nativeMouse(elm) {
103 var position = Elm.Signal.constant(Value.Tuple(0,0));
114 position.defaultNumberOfKids = 2;
125
13− /** x : Signal Int
14− The current x-coordinate of the mouse.
15− **/
16− var x = Elm.Signal.lift(function(p){return p[1];})(position);
6+ // do not get rid of x and y. By setting their default number
7+ // of kids, it is possible to detatch the mouse listeners if
8+ // they are not needed.
9+ var x = Elm.Signal.lift(function(p){return p._0})(position);
1710 x.defaultNumberOfKids = 0;
18−
19− /** y : Signal Int
20− The current y-coordinate of the mouse.
21− **/
22− var y = Elm.Signal.lift(function(p){return p[2];})(position);
11+ var y = Elm.Signal.lift(function(p){return p._1})(position);
2312 y.defaultNumberOfKids = 0;
2413
25− /*[Button Status]*/
26−
27− /** isDown : Signal Bool
28− The current state of the left mouse-button.
29− True when the button is down, and false otherwise.
30− **/
3114 var isDown = Elm.Signal.constant(false);
32−
33− /** isClicked : Signal Bool
34− True immediately after the left mouse-button has been clicked,
35− and false otherwise.
36− **/
3715 var isClicked = Elm.Signal.constant(false);
38−
39− /** clicks : Signal ()
40− Always equal to unit. Event triggers on every mouse click.
41− **/
4216 var clicks = Elm.Signal.constant(Value.Tuple());
4317
4418 function getXY(e) {
@@ -80,12 +54,6 @@ Elm.Mouse = function() {
8054 this.removeEventListener('mousemove',arguments.callee,false);
8155 });
8256
83− /** isClickedOn : Element -> (Element, Signal Bool)
84− Determine whether an element has been clicked. The resulting pair
85− is a signal of booleans that is true when its paired element has
86− been clicked. The signal is True immediately after the left
87− mouse-button has been clicked, and false otherwise.
88− **/
8957 var clickedOn = function(elem) {
9058 var node = Render.render(elem);
9159 var click = Elm.Signal.constant(false);
@@ -95,12 +63,11 @@ Elm.Mouse = function() {
9563 });
9664 return Value.Tuple(Value.wrap(node), click);
9765 };
98− return {position: position,
99− x:x,
100− y:y,
101− isClicked: isClicked,
102− isDown: isDown,
103− clicks: clicks,
104− isClickedOn: clickedOn
105− };
106− }();
66+ elm.Native.Mouse = {position: position,
67+ x:x,
68+ y:y,
69+ isClicked: isClicked,
70+ isDown: isDown,
71+ clicks: clicks,
72+ isClickedOn: clickedOn};
73+}