2Elm.Native.Touch = function(elm) {
5 elm.Native = elm.Native || {};
6 if (elm.Native.Touch) return elm.Native.Touch;
8 var Signal = Elm.Signal(elm);
9 var JS = Elm.JavaScript(elm);
10 var _ = Elm.Native.Utils(elm);
16 this.insert = function(key,value) {
18 this.values.push(value);
20 this.lookup = function(key) {
21 var i = this.keys.indexOf(key)
22 return i >= 0 ? this.values[i] : {x:0,y:0,t:0};
24 this.remove = function(key) {
25 var i = this.keys.indexOf(key);
27 var t = this.values[i];
28 this.keys.splice(i,1);
29 this.values.splice(i,1);
32 this.clear = function() {
38 var root = Signal.constant([]),
45 var r = dict.lookup(t.identifier);
48 x : t.pageX - elm.node.offsetX,
49 y : t.pageY - elm.node.offsetY,
56 var node = elm.display === ElmRuntime.Display.FULLSCREEN ? document : elm.node;
59 dict.insert(e.identifier,
60 {x: e.pageX - elm.node.offsetX,
61 y: e.pageY - elm.node.offsetY,
65 var t = dict.remove(e.identifier);
66 if (Date.now() - t.t < tapTime) {
68 tap = {_:{}, x:t.x, y:t.y};
72 function listen(name, f) {
74 for (var i = e.changedTouches.length; i--; ) { f(e.changedTouches[i]); }
75 var ts = new Array(e.touches.length);
76 for (var i = e.touches.length; i--; ) { ts[i] = touch(e.touches[i]); }
77 elm.notify(root.id, ts);
80 elm.addListener([root.id], node, name, update);
83 listen("touchstart", start);
84 listen("touchmove", function(_){});
85 listen("touchend", end);
86 listen("touchcancel", end);
87 listen("touchleave", end);
91 for (var i = root.value.length; i--; ) {
92 if (root.value[i].id === mouseID) {
93 root.value[i].x = e.pageX - elm.node.offsetX;
94 root.value[i].y = e.pageY - elm.node.offsetY;
95 elm.notify(root.id, root.value);
100 elm.addListener([root.id], node, "mousedown", function down(e) {
101 node.addEventListener("mousemove", move);
102 e.identifier = mouseID;
104 root.value.push(touch(e));
105 elm.notify(root.id, root.value);
107 elm.addListener([root.id], node, "mouseup", function up(e) {
108 node.removeEventListener("mousemove", move);
109 e.identifier = mouseID;
111 for (var i = root.value.length; i--; ) {
112 if (root.value[i].id === mouseID) {
113 root.value.splice(i, 1);
118 elm.notify(root.id, root.value);
120 elm.addListener([root.id], node, "blur", function blur(e) {
121 node.removeEventListener("mousemove", move);
122 if (root.values.length > 0) {
123 elm.notify(root.id, []);
129 function dependency(f) {
130 var sig = A2( Signal.lift, f, root );
131 root.defaultNumberOfKids += 1;
132 sig.defaultNumberOfKids = 0;
136 var touches = dependency(JS.toList);
138 var taps = function() {
139 var sig = dependency(function(_) { return tap; });
140 sig.defaultNumberOfKids = 1;
141 function pred(_) { var b = hasTap; hasTap = false; return b; }
142 var sig2 = A3( Signal.keepIf, pred, {_:{},x:0,y:0}, sig);
143 sig2.defaultNumberOfKids = 0;
147 return elm.Native.Touch = { touches: touches, taps: taps };
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