Filter touch events not to be handled.

In IE 10/11, MSPointer event is fired by mouse. It shouldn't be handled.

Also, Exception has occurred with event.targetTouches, and this commit
fixed it too.
This commit is contained in:
Hyunje Alex Jun 2014-10-24 11:26:54 +01:00
parent 494d68fe02
commit 7dd6335965

View File

@ -544,6 +544,7 @@
var speed = {}; var speed = {};
var breakingProcess = null; var breakingProcess = null;
var inGlobalTouch = false; var inGlobalTouch = false;
var inLocalTouch = false;
function globalTouchStart(e) { function globalTouchStart(e) {
inGlobalTouch = true; inGlobalTouch = true;
@ -560,7 +561,20 @@
return e.originalEvent; return e.originalEvent;
} }
} }
function shouldHandle(e) {
var event = e.originalEvent;
if (event.targetTouches && event.targetTouches.length === 1) {
return true;
}
if (event.pointerType && event.pointerType !== 'mouse') {
return true;
}
return false;
}
function touchStart(e) { function touchStart(e) {
if (shouldHandle(e)) {
inLocalTouch = true;
var touch = getTouch(e); var touch = getTouch(e);
startOffset.pageX = touch.pageX; startOffset.pageX = touch.pageX;
@ -575,8 +589,9 @@
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
} }
}
function touchMove(e) { function touchMove(e) {
if (!inGlobalTouch && e.originalEvent.targetTouches.length === 1) { if (!inGlobalTouch && inLocalTouch && shouldHandle(e)) {
var touch = getTouch(e); var touch = getTouch(e);
var currentOffset = {pageX: touch.pageX, pageY: touch.pageY}; var currentOffset = {pageX: touch.pageX, pageY: touch.pageY};
@ -601,6 +616,9 @@
} }
} }
function touchEnd(e) { function touchEnd(e) {
if (!inGlobalTouch && inLocalTouch) {
inLocalTouch = false;
clearInterval(breakingProcess); clearInterval(breakingProcess);
breakingProcess = setInterval(function () { breakingProcess = setInterval(function () {
if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) { if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
@ -614,6 +632,7 @@
speed.y *= 0.8; speed.y *= 0.8;
}, 10); }, 10);
} }
}
if (supportsTouch) { if (supportsTouch) {
$(window).bind("touchstart" + eventClassName, globalTouchStart); $(window).bind("touchstart" + eventClassName, globalTouchStart);