123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- $(function() {
-
-
-
- $.extend($.support, {
- touch: typeof Touch == "object"
- });
-
-
-
-
- if ($.support.touch) {
- document.addEventListener("touchstart", iPadTouchHandler, false);
- document.addEventListener("touchmove", iPadTouchHandler, false);
- document.addEventListener("touchend", iPadTouchHandler, false);
- document.addEventListener("touchcancel", iPadTouchHandler, false);
- }
- });
- var lastTap = null;
- var tapValid = false;
- var tapTimeout = null;
- function cancelTap() {
- tapValid = false;
- }
- var rightClickPending = false;
- var rightClickEvent = null;
- var holdTimeout = null;
- var cancelMouseUp = false;
- function cancelHold() {
- if (rightClickPending) {
- window.clearTimeout(holdTimeout);
- rightClickPending = false;
- rightClickEvent = null;
- }
- }
- function startHold(event) {
- if (rightClickPending)
- return;
- rightClickPending = true;
- rightClickEvent = (event.changedTouches)[0];
- holdTimeout = window.setTimeout("doRightClick();", 800);
- }
- function doRightClick() {
- rightClickPending = false;
-
-
-
- var first = rightClickEvent,
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent("mouseup", true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, 0, null);
- first.target.dispatchEvent(simulatedEvent);
-
-
-
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent("mousedown", true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, 2, null);
- first.target.dispatchEvent(simulatedEvent);
-
-
-
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent("contextmenu", true, true, window, 1, first.screenX + 50, first.screenY + 5, first.clientX + 50, first.clientY + 5,
- false, false, false, false, 2, null);
- first.target.dispatchEvent(simulatedEvent);
-
-
-
- cancelMouseUp = true;
- rightClickEvent = null;
- }
- function iPadTouchStart(event) {
- var touches = event.changedTouches,
- first = touches[0],
- type = "mouseover",
- simulatedEvent = document.createEvent("MouseEvent");
-
-
-
- simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, 0, null);
- first.target.dispatchEvent(simulatedEvent);
- type = "mousedown";
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, 0, null);
- first.target.dispatchEvent(simulatedEvent);
- if (!tapValid) {
- lastTap = first.target;
- tapValid = true;
- tapTimeout = window.setTimeout("cancelTap();", 600);
- startHold(event);
- }
- else {
- window.clearTimeout(tapTimeout);
-
-
-
-
- if (first.target == lastTap) {
- lastTap = null;
- tapValid = false;
- type = "click";
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, 0, null);
- first.target.dispatchEvent(simulatedEvent);
- type = "dblclick";
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, 0, null);
- first.target.dispatchEvent(simulatedEvent);
- }
- else {
- lastTap = first.target;
- tapValid = true;
- tapTimeout = window.setTimeout("cancelTap();", 600);
- startHold(event);
- }
- }
- }
- function iPadTouchHandler(event) {
- var type = "",
- button = 0;
- if (event.touches.length > 1)
- return;
- switch (event.type) {
- case "touchstart":
- if ($(event.changedTouches[0].target).is("select")) {
- return;
- }
- iPadTouchStart(event);
- event.preventDefault();
- return false;
- break;
- case "touchmove":
- cancelHold();
- type = "mousemove";
- event.preventDefault();
- break;
- case "touchend":
- if (cancelMouseUp) {
- cancelMouseUp = false;
- event.preventDefault();
- return false;
- }
- cancelHold();
- type = "mouseup";
- break;
- default:
- return;
- }
- var touches = event.changedTouches,
- first = touches[0],
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, button, null);
- first.target.dispatchEvent(simulatedEvent);
- if (type == "mouseup" && tapValid && first.target == lastTap) {
- simulatedEvent = document.createEvent("MouseEvent");
- simulatedEvent.initMouseEvent("click", true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
- false, false, false, false, button, null);
- first.target.dispatchEvent(simulatedEvent);
- }
- }
|