Simplify touch event implementation
This commit is contained in:
parent
131dc8397d
commit
80eb357527
@ -156,28 +156,30 @@ class Frontend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onTouchStart(e) {
|
onTouchStart(e) {
|
||||||
if (this.primaryTouchIdentifier !== null && this.getIndexOfTouch(e.touches, this.primaryTouchIdentifier) >= 0) {
|
if (
|
||||||
|
this.primaryTouchIdentifier !== null ||
|
||||||
|
e.changedTouches.length === 0
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let touch = this.getPrimaryTouch(e.changedTouches);
|
const primaryTouch = e.changedTouches[0];
|
||||||
if (Frontend.selectionContainsPoint(window.getSelection(), touch.clientX, touch.clientY)) {
|
if (Frontend.selectionContainsPoint(window.getSelection(), primaryTouch.clientX, primaryTouch.clientY)) {
|
||||||
touch = null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setPrimaryTouch(touch);
|
this.setPrimaryTouch(primaryTouch);
|
||||||
}
|
}
|
||||||
|
|
||||||
onTouchEnd(e) {
|
onTouchEnd(e) {
|
||||||
if (this.primaryTouchIdentifier === null) {
|
if (
|
||||||
|
this.primaryTouchIdentifier === null ||
|
||||||
|
this.getIndexOfTouch(e.changedTouches, this.primaryTouchIdentifier) < 0
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getIndexOfTouch(e.changedTouches, this.primaryTouchIdentifier) < 0) {
|
this.setPrimaryTouch(null);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setPrimaryTouch(this.getPrimaryTouch(this.excludeTouches(e.touches, e.changedTouches)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onTouchCancel(e) {
|
onTouchCancel(e) {
|
||||||
@ -195,8 +197,8 @@ class Frontend {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const touch = touches[index];
|
const primaryTouch = touches[index];
|
||||||
this.searchAt(touch.clientX, touch.clientY, 'touchMove');
|
this.searchAt(primaryTouch.clientX, primaryTouch.clientY, 'touchMove');
|
||||||
|
|
||||||
e.preventDefault(); // Disable scroll
|
e.preventDefault(); // Disable scroll
|
||||||
}
|
}
|
||||||
@ -407,10 +409,6 @@ class Frontend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPrimaryTouch(touchList) {
|
|
||||||
return touchList.length > 0 ? touchList[0] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
getIndexOfTouch(touchList, identifier) {
|
getIndexOfTouch(touchList, identifier) {
|
||||||
for (let i in touchList) {
|
for (let i in touchList) {
|
||||||
let t = touchList[i];
|
let t = touchList[i];
|
||||||
@ -421,16 +419,6 @@ class Frontend {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
excludeTouches(touchList, excludeTouchList) {
|
|
||||||
const result = [];
|
|
||||||
for (let r of touchList) {
|
|
||||||
if (this.getIndexOfTouch(excludeTouchList, r.identifier) < 0) {
|
|
||||||
result.push(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
setPrimaryTouch(touch) {
|
setPrimaryTouch(touch) {
|
||||||
if (touch === null) {
|
if (touch === null) {
|
||||||
this.primaryTouchIdentifier = null;
|
this.primaryTouchIdentifier = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user