-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtouch_event.js
48 lines (41 loc) · 1.05 KB
/
touch_event.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
var Lib = require('../../../src/lib');
module.exports = function(type, x, y, opts) {
var el = (opts && opts.element) || document.elementFromPoint(x, y);
var ev;
var touchObj = new Touch({
identifier: Date.now(),
target: el,
clientX: x,
clientY: y,
screenX: x,
screenY: y,
pageX: x,
pageY: y,
radiusX: 2.5,
radiusY: 2.5,
rotationAngle: 10,
force: 0.5,
});
var fullOpts = {
touches: [touchObj],
targetTouches: [],
changedTouches: [touchObj],
bubbles: true,
cancelable: true
};
if(opts && opts.altKey) {
fullOpts.altKey = opts.altKey;
}
if(opts && opts.ctrlKey) {
fullOpts.ctrlKey = opts.ctrlKey;
}
if(opts && opts.metaKey) {
fullOpts.metaKey = opts.metaKey;
}
if(opts && opts.shiftKey) {
fullOpts.shiftKey = opts.shiftKey;
}
ev = new window.TouchEvent(type, Lib.extendFlat({}, fullOpts, opts));
if(el) el.dispatchEvent(ev);
return el;
};