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);
15 this.insert = function(key,value) {
17 this.values.push(value);
19 this.lookup = function(key) {
20 var i = this.keys.indexOf(key)
21 return i >= 0 ? this.values[i] : {x:0,y:0,t:0};
23 this.remove = function(key) {
24 var i = this.keys.indexOf(key);
26 var t = this.values[i];
27 this.keys.splice(i,1);
28 this.values.splice(i,1);
33 var root = Signal.constant([]),
40 var r = dict.lookup(t.identifier);
52 dict.insert(e.identifier,{x:e.pageX,y:e.pageY,t:Date.now()});
55 var t = dict.remove(e.identifier);
56 if (Date.now() - t.t < tapTime) {
58 tap = {_:{}, x:t.x, y:t.y};
62 function listen(name, f) {
64 for (var i = e.changedTouches.length; i--; ) { f(e.changedTouches[i]); }
65 var ts = new Array(e.touches.length);
66 for (var i = e.touches.length; i--; ) { ts[i] = touch(e.touches[i]); }
67 var hasListener = elm.notify(root.id, ts);
68 if (!hasListener) return elm.node.removeEventListener(name, update);
71 elm.node.addEventListener(name, update);
74 listen("touchstart", start);
75 listen("touchmove", function(_){});
76 listen("touchend", end);
77 listen("touchcancel", end);
78 listen("touchleave", end);
80 function dependency(f) {
81 var sig = A2( Signal.lift, f, root );
82 root.defaultNumberOfKids += 1;
83 sig.defaultNumberOfKids = 0;
87 var touches = dependency(JS.fromList);
89 var taps = function() {
90 var sig = dependency(function(_) { return tap; });
91 sig.defaultNumberOfKids = 1;
92 function pred(_) { var b = hasTap; hasTap = false; return b; }
93 var sig2 = A3( Signal.keepIf, pred, {_:{},x:0,y:0}, sig);
94 sig2.defaultNumberOfKids = 0;
98 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