-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind_touch_forwarding.js
More file actions
57 lines (40 loc) · 1.63 KB
/
bind_touch_forwarding.js
File metadata and controls
57 lines (40 loc) · 1.63 KB
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
define( function () {
'use strict';
/*
Bind and forward touch events to provided mouse handlers
---
element obj HTML element object where events were bound
startHandler func Handler function to forward touchstart events to
moveHandler func Handler function to forward touchmove events to
endHandler func Handler function to forward touchend events to
--
Returns arr Array containing the touch event handlers
*/
return function (element, downHandler, moveHandler, upHandler) {
var bindDown = function (e) {
e.clientX = e.touches[0].clientX;
e.clientY = e.touches[0].clientY;
e.pageX = e.touches[0].pageX;
e.pageY = e.touches[0].pageY;
downHandler( e );
};
var bindMove = function (e) {
e.clientX = e.touches[0].clientX;
e.clientY = e.touches[0].clientY;
e.pageX = e.touches[0].pageX;
e.pageY = e.touches[0].pageY;
moveHandler( e );
};
var bindUp = function (e) {
e.clientX = e.changedTouches[0].clientX;
e.clientY = e.changedTouches[0].clientY;
e.pageX = e.changedTouches[0].pageX;
e.pageY = e.changedTouches[0].pageY;
upHandler( e );
};
element.addEventListener( 'touchstart', bindDown, false );
element.addEventListener( 'touchmove', bindMove, false );
element.addEventListener( 'touchend', bindUp, false );
return [ bindDown, bindMove, bindUp ];
};
});