-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
62 lines (53 loc) · 1.53 KB
/
index.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
var on = require("dom-event");
module.exports = simulate;
function simulate (element) {
on(element, 'mousedown', dispatch('touchstart'));
on(element, 'mousemove', dispatch('touchmove'));
on(element, 'mouseup', dispatch('touchend'));
}
function dispatch (touchEventType) {
return function (event) {
var touchEvent;
try {
touchEvent = newTouchEvent({
type: touchEventType,
event: event
});
} catch (err) {
// failed to create a mouse event just ignore
return;
}
touchEvent.changedTouches = touchEvent.touches = [{
identifier: Date.now() + Math.random(),
clientX: event.clientX,
clientY: event.clientY,
pageX: event.pageX,
pageY: event.pageY,
screenX: event.screenX,
screenY: event.screenY
}];
event.target.dispatchEvent(touchEvent);
};
}
function newTouchEvent (options) {
var touchEvent = document.createEvent('MouseEvents');
touchEvent.initMouseEvent(
options.type,
true, // bubbles
true, // cancelable
window, // view
1, // detail
options.event.screenX, // screenX
options.event.screenY, // screenY
options.event.clientX, // clientX
options.event.clientY, // clientY
options.event.pageX, // pageX
options.event.pageY, // pageY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null);
return touchEvent;
}