forked from dojo/dojo-oldmirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch.js
99 lines (96 loc) · 3.25 KB
/
touch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
define(["./_base/kernel", "./on", "./has", "./mouse"], function(dojo, on, has, mouse){
// module:
// dojo/touch
/*=====
dojo.touch = {
// summary:
// This module provides unified touch event handlers by exporting
// press, move, release and cancel which can also run well on desktop.
// Based on http://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html
//
// example:
// 1. Used with dojo.connect()
// | dojo.connect(node, dojo.touch.press, function(e){});
// | dojo.connect(node, dojo.touch.move, function(e){});
// | dojo.connect(node, dojo.touch.release, function(e){});
// | dojo.connect(node, dojo.touch.cancel, function(e){});
//
// 2. Used with dojo.on
// | define(["dojo/on", "dojo/touch"], function(on, touch){
// | on(node, touch.press, function(e){});
// | on(node, touch.move, function(e){});
// | on(node, touch.release, function(e){});
// | on(node, touch.cancel, function(e){});
//
// 3. Used with dojo.touch.* directly
// | dojo.touch.press(node, function(e){});
// | dojo.touch.move(node, function(e){});
// | dojo.touch.release(node, function(e){});
// | dojo.touch.cancel(node, function(e){});
press: function(node, listener){
// summary:
// Register a listener to 'touchstart'|'mousedown' for the given node
// node: Dom
// Target node to listen to
// listener: Function
// Callback function
// returns:
// A handle which will be used to remove the listener by handle.remove()
},
move: function(node, listener){
// summary:
// Register a listener to 'touchmove'|'mousemove' for the given node
// node: Dom
// Target node to listen to
// listener: Function
// Callback function
// returns:
// A handle which will be used to remove the listener by handle.remove()
},
release: function(node, listener){
// summary:
// Register a listener to 'touchend'|'mouseup' for the given node
// node: Dom
// Target node to listen to
// listener: Function
// Callback function
// returns:
// A handle which will be used to remove the listener by handle.remove()
},
cancel: function(node, listener){
// summary:
// Register a listener to 'touchcancel'|'mouseleave' for the given node
// node: Dom
// Target node to listen to
// listener: Function
// Callback function
// returns:
// A handle which will be used to remove the listener by handle.remove()
}
};
=====*/
function _handle(/*String*/ type){
return function(node, listener){//called by on(), see dojo.on
return on(node, type, listener);
};
}
var touch = has("touch");
//device neutral events - dojo.touch.press|move|release|cancel
return dojo.touch = {
press: _handle("mousedown" + (touch ? ",touchstart" : "")),
move: _handle("mousemove" + (touch ? ",touchmove" : "")),
release: _handle("mouseup" + (touch ? ",touchend" : "")),
cancel: !touch ? mouse.leave : function(node, listener){
// If touch is supported, hook up handlers for both touchcancel and
// mouse.leave, returning an object with a remove function to unhook both.
var mconn = on(node, mouse.leave, listener),
tconn = on(node, "touchcancel", listener);
return {
remove: function(){
mconn.remove();
tconn.remove();
}
};
}
};
});