1 | function touchHandler(event)
|
---|
2 | {
|
---|
3 |
|
---|
4 | var touches = event.changedTouches,
|
---|
5 | first = touches[0],
|
---|
6 | type = "";
|
---|
7 | switch(event.type)
|
---|
8 | {
|
---|
9 | case "touchstart": type="mousedown"; break;
|
---|
10 | case "touchmove": type="mousemove"; break;
|
---|
11 | case "touchend": type="mouseup"; break;
|
---|
12 | default: return;
|
---|
13 | }
|
---|
14 |
|
---|
15 | //initMouseEvent(type, canBubble, cancelable, view, clickCount,
|
---|
16 | // screenX, screenY, clientX, clientY, ctrlKey,
|
---|
17 | // altKey, shiftKey, metaKey, button, relatedTarget);
|
---|
18 |
|
---|
19 | var simulatedEvent = document.createEvent("MouseEvent");
|
---|
20 | simulatedEvent.initMouseEvent(type, true, true, window, 1,
|
---|
21 | first.screenX, first.screenY,
|
---|
22 | first.clientX, first.clientY, false,
|
---|
23 | false, false, false, 0/*left*/, null);
|
---|
24 | if(touches.length < 2) {
|
---|
25 | first.target.dispatchEvent(simulatedEvent);
|
---|
26 | event.preventDefault();
|
---|
27 | }
|
---|
28 | }
|
---|