Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Oct 11, 2021
1 parent e05ec73 commit f90c0ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions js/src/util/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Swipe {
}

this._config = this._getConfig(config)
this._startX = 0
this._deltaX = 0
this._supportPointerEvents = Boolean(window.PointerEvent)
this._initEvents()
}
Expand All @@ -45,41 +45,41 @@ class Swipe {

_start(event) {
if (!this._supportPointerEvents) {
this._startX = event.touches[0].clientX
this._deltaX = event.touches[0].clientX

return
}

if (this._eventIsPointerPenTouch(event)) {
this._startX = event.clientX
this._deltaX = event.clientX
}
}

_end(event) {
if (this._eventIsPointerPenTouch(event)) {
this._startX = event.clientX - this._startX
this._deltaX = event.clientX - this._deltaX
}

this._handleSwipe()
execute(this._config.endCallback)
}

_move(event) {
this._startX = event.touches && event.touches.length > 1 ?
this._deltaX = event.touches && event.touches.length > 1 ?
0 :
event.touches[0].clientX - this._startX
event.touches[0].clientX - this._deltaX
}

_handleSwipe() {
const absDeltaX = Math.abs(this._startX)
const absDeltaX = Math.abs(this._deltaX)

if (absDeltaX <= SWIPE_THRESHOLD) {
return
}

const direction = absDeltaX / this._startX
const direction = absDeltaX / this._deltaX

this._startX = 0
this._deltaX = 0

if (!direction) {
return
Expand Down
2 changes: 1 addition & 1 deletion js/tests/unit/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ describe('Carousel', () => {
}, () => {
restorePointerEvents()
delete document.documentElement.ontouchstart
expect(carousel._swipeHelper._startX).toEqual(0)
expect(carousel._swipeHelper._deltaX).toEqual(0)
done()
})
})
Expand Down

0 comments on commit f90c0ea

Please sign in to comment.