@@ -2,23 +2,26 @@
22Elm.Touch = function() {
33 var touches = Elm.Signal.constant(["Nil"]);
44
5− Value.addListener(document, "touchstart", function(e) {
6− var ts = e.changedTouches;
7− var vs = touches.value;
8− for (var i = ts.length; i--; ) {
9− var t = ts[i];
10− vs = ["Cons", Value.tuple(t.pageX, t.pageY), vs];
11− }
12− Dispatcher.notify(touches.id, vs);
13− });
14− Value.addListener(document, "touchend", function(e) {
15− });
16− Value.addListener(document, "touchcancel", function(e) {
17− });
18− Value.addListener(document, "touchleave", function(e) {
19− });
20− Value.addListener(document, "touchmove", function(e) {
21− });
5+ function touch(t) {
6+ return {_ : [true], x: [t.pageX], y: [t.pageY], id: [t.identifier] };
7+ }
228
23− return {};
9+ function listen(name) {
10+ function update(e) {
11+ var ts = Elm.JavaScript.castJSArrayToList(e.touches);
12+ var hasListener = Dispatcher.notify(touches.id, Elm.List.map(touch)(ts));
13+ if (!hasListener)
14+ return this.removeEventListener(name,arguments.callee,false);
15+ e.preventDefault();
16+ }
17+ Value.addListener(document, name, update);
18+ }
19+
20+ listen("touchstart");
21+ listen("touchmove");
22+ listen("touchend");
23+ listen("touchcancel");
24+ listen("touchleave");
25+
26+ return { touches: touches };
2427}();