Return early if no relevant touches
This commit is contained in:
parent
0c401e0247
commit
90922d85c6
1 changed files with 27 additions and 12 deletions
|
|
@ -277,11 +277,12 @@ var touchpad = (function() {
|
||||||
moved = false;
|
moved = false;
|
||||||
}
|
}
|
||||||
var touches = evt.changedTouches;
|
var touches = evt.changedTouches;
|
||||||
|
var foundTouch = false;
|
||||||
for (var i = 0; i < touches.length; i += 1) {
|
for (var i = 0; i < touches.length; i += 1) {
|
||||||
if (ongoingTouches.length == 0 && !touches[i].target.classList.contains("touch")) {
|
if (ongoingTouches.length == 0 && !touches[i].target.classList.contains("touch")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
evt.preventDefault();
|
foundTouch = true;
|
||||||
var touch = copyTouch(touches[i], evt.timeStamp);
|
var touch = copyTouch(touches[i], evt.timeStamp);
|
||||||
var idx = ongoingTouchIndexById(touch.identifier);
|
var idx = ongoingTouchIndexById(touch.identifier);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
|
|
@ -289,6 +290,11 @@ var touchpad = (function() {
|
||||||
} else {
|
} else {
|
||||||
ongoingTouches[idx] = touch;
|
ongoingTouches[idx] = touch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!foundTouch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
evt.preventDefault();
|
||||||
lastEndTimeStamp = 0;
|
lastEndTimeStamp = 0;
|
||||||
if (draggingTimeout != null) {
|
if (draggingTimeout != null) {
|
||||||
clearTimeout(draggingTimeout);
|
clearTimeout(draggingTimeout);
|
||||||
|
|
@ -296,22 +302,26 @@ var touchpad = (function() {
|
||||||
dragging = true;
|
dragging = true;
|
||||||
}
|
}
|
||||||
controller.pointerScroll(0, 0, true);
|
controller.pointerScroll(0, 0, true);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
touchpad.handleTouchend = touchpad.handleTouchcancel = function(evt) {
|
touchpad.handleTouchend = touchpad.handleTouchcancel = function(evt) {
|
||||||
var touches = evt.changedTouches;
|
var touches = evt.changedTouches;
|
||||||
|
var foundTouch = false;
|
||||||
for (var i = 0; i < touches.length; i += 1) {
|
for (var i = 0; i < touches.length; i += 1) {
|
||||||
var idx = ongoingTouchIndexById(touches[i].identifier);
|
var idx = ongoingTouchIndexById(touches[i].identifier);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
evt.preventDefault();
|
foundTouch = true;
|
||||||
ongoingTouches.splice(idx, 1);
|
ongoingTouches.splice(idx, 1);
|
||||||
releasedCount += 1;
|
releasedCount += 1;
|
||||||
|
}
|
||||||
|
if (!foundTouch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
evt.preventDefault();
|
||||||
lastEndTimeStamp = evt.timeStamp;
|
lastEndTimeStamp = evt.timeStamp;
|
||||||
controller.pointerScroll(0, 0, true);
|
controller.pointerScroll(0, 0, true);
|
||||||
}
|
|
||||||
if (releasedCount > TOUCH_MOVE_THRESHOLD.length) {
|
if (releasedCount > TOUCH_MOVE_THRESHOLD.length) {
|
||||||
moved = true;
|
moved = true;
|
||||||
}
|
}
|
||||||
|
|
@ -344,12 +354,13 @@ var touchpad = (function() {
|
||||||
var sumX = 0;
|
var sumX = 0;
|
||||||
var sumY = 0;
|
var sumY = 0;
|
||||||
var touches = evt.changedTouches;
|
var touches = evt.changedTouches;
|
||||||
|
var foundTouch = false;
|
||||||
for (var i = 0; i < touches.length; i += 1) {
|
for (var i = 0; i < touches.length; i += 1) {
|
||||||
var idx = ongoingTouchIndexById(touches[i].identifier);
|
var idx = ongoingTouchIndexById(touches[i].identifier);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
evt.preventDefault();
|
foundTouch = true;
|
||||||
if (!moved) {
|
if (!moved) {
|
||||||
var dist = Math.sqrt(Math.pow(touches[i].pageX - ongoingTouches[idx].pageXStart, 2) +
|
var dist = Math.sqrt(Math.pow(touches[i].pageX - ongoingTouches[idx].pageXStart, 2) +
|
||||||
Math.pow(touches[i].pageY - ongoingTouches[idx].pageYStart, 2));
|
Math.pow(touches[i].pageY - ongoingTouches[idx].pageYStart, 2));
|
||||||
|
|
@ -368,6 +379,10 @@ var touchpad = (function() {
|
||||||
ongoingTouches[idx].pageY = touches[i].pageY;
|
ongoingTouches[idx].pageY = touches[i].pageY;
|
||||||
ongoingTouches[idx].timeStamp = evt.timeStamp;
|
ongoingTouches[idx].timeStamp = evt.timeStamp;
|
||||||
}
|
}
|
||||||
|
if (!foundTouch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
evt.preventDefault();
|
||||||
if (moved && evt.timeStamp - lastEndTimeStamp >= TOUCH_TIMEOUT) {
|
if (moved && evt.timeStamp - lastEndTimeStamp >= TOUCH_TIMEOUT) {
|
||||||
if (ongoingTouches.length == 1 || dragging) {
|
if (ongoingTouches.length == 1 || dragging) {
|
||||||
controller.pointerMove(sumX*config.moveSpeed, sumY*config.moveSpeed);
|
controller.pointerMove(sumX*config.moveSpeed, sumY*config.moveSpeed);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue