Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Oct 11, 2021
1 parent 8d8857b commit e05ec73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 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._xDown = 0
this._startX = 0
this._supportPointerEvents = Boolean(window.PointerEvent)
this._initEvents()
}
Expand All @@ -45,41 +45,41 @@ class Swipe {

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

return
}

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

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

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

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

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

if (absDeltaX <= SWIPE_THRESHOLD) {
return
}

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

this._xDown = 0
this._startX = 0

if (!direction) {
return
Expand Down Expand Up @@ -110,7 +110,7 @@ class Swipe {
return config
}

_eventIsNotSwipe(event) {
_eventIsPointerPenTouch(event) {
return this._supportPointerEvents && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)
}

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._xDown).toEqual(0)
expect(carousel._swipeHelper._startX).toEqual(0)
done()
})
})
Expand Down

0 comments on commit e05ec73

Please sign in to comment.