diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-24 21:36:18 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-28 17:03:42 -0400 |
commit | 80eb3575276e6499824b4ac71782f1a6c87c43ac (patch) | |
tree | c9217c2760eef30ff695ec3c732df41751bfbcd3 /ext/fg/js | |
parent | 131dc8397dd453839843dbdc493dc721e51496fb (diff) |
Simplify touch event implementation
Diffstat (limited to 'ext/fg/js')
-rw-r--r-- | ext/fg/js/frontend.js | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 8a08f105..223088a1 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -156,28 +156,30 @@ class Frontend { } onTouchStart(e) { - if (this.primaryTouchIdentifier !== null && this.getIndexOfTouch(e.touches, this.primaryTouchIdentifier) >= 0) { + if ( + this.primaryTouchIdentifier !== null || + e.changedTouches.length === 0 + ) { return; } - let touch = this.getPrimaryTouch(e.changedTouches); - if (Frontend.selectionContainsPoint(window.getSelection(), touch.clientX, touch.clientY)) { - touch = null; + const primaryTouch = e.changedTouches[0]; + if (Frontend.selectionContainsPoint(window.getSelection(), primaryTouch.clientX, primaryTouch.clientY)) { + return; } - this.setPrimaryTouch(touch); + this.setPrimaryTouch(primaryTouch); } onTouchEnd(e) { - if (this.primaryTouchIdentifier === null) { - return; - } - - if (this.getIndexOfTouch(e.changedTouches, this.primaryTouchIdentifier) < 0) { + if ( + this.primaryTouchIdentifier === null || + this.getIndexOfTouch(e.changedTouches, this.primaryTouchIdentifier) < 0 + ) { return; } - this.setPrimaryTouch(this.getPrimaryTouch(this.excludeTouches(e.touches, e.changedTouches))); + this.setPrimaryTouch(null); } onTouchCancel(e) { @@ -195,8 +197,8 @@ class Frontend { return; } - const touch = touches[index]; - this.searchAt(touch.clientX, touch.clientY, 'touchMove'); + const primaryTouch = touches[index]; + this.searchAt(primaryTouch.clientX, primaryTouch.clientY, 'touchMove'); e.preventDefault(); // Disable scroll } @@ -407,10 +409,6 @@ class Frontend { } } - getPrimaryTouch(touchList) { - return touchList.length > 0 ? touchList[0] : null; - } - getIndexOfTouch(touchList, identifier) { for (let i in touchList) { let t = touchList[i]; @@ -421,16 +419,6 @@ class Frontend { 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) { if (touch === null) { this.primaryTouchIdentifier = null; |