Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private checkClick(e: TouchEvent) {
// when in the process of pulling down, it should not prevent click
const cancelable = {
preventClick: this.animater.forceStopped
}
// we scrolled less than momentumLimitDistance pixels
if (this.hooks.trigger(this.hooks.eventTypes.checkClick)) return true
if (!cancelable.preventClick) {
const _dblclick = this.options.dblclick
let dblclickTrigged = false
if (_dblclick && this.lastClickTime) {
const { delay = 300 } = _dblclick as any
if (getNow() - this.lastClickTime < delay) {
dblclickTrigged = true
dblclick(e)
}
}
if (this.options.tap) {
tap(e, this.options.tap)
}
if (
this.options.click &&
!preventDefaultExceptionFn(
e.target,
this.options.preventDefaultException
)
) {
click(e)
}
private handleStart(e: TouchEvent) {
const timestamp = getNow()
this.moved = false
this.startTime = timestamp
this.directionLockAction.reset()
this.scrollBehaviorX.start()
this.scrollBehaviorY.start()
// force stopping last transition or animation
this.animater.stop()
this.scrollBehaviorX.resetStartPos()
this.scrollBehaviorY.resetStartPos()
this.hooks.trigger(this.hooks.eventTypes.start, e)
private handleMove(deltaX: number, deltaY: number, e: TouchEvent) {
if (this.hooks.trigger(this.hooks.eventTypes.beforeMove, e)) {
return
}
const absDistX = this.scrollBehaviorX.getAbsDist(deltaX)
const absDistY = this.scrollBehaviorY.getAbsDist(deltaY)
const timestamp = getNow()
// We need to move at least momentumLimitDistance pixels
// for the scrolling to initiate
if (this.checkMomentum(absDistX, absDistY, timestamp)) {
return true
}
if (this.directionLockAction.checkMovingDirection(absDistX, absDistY, e)) {
this.actionsHandler.setInitiated()
return true
}
const delta = this.directionLockAction.adjustDelta(deltaX, deltaY)
const newX = this.scrollBehaviorX.move(delta.deltaX)
const newY = this.scrollBehaviorY.move(delta.deltaY)
dblclick(e)
}
}
if (this.options.tap) {
tap(e, this.options.tap)
}
if (
this.options.click &&
!preventDefaultExceptionFn(
e.target,
this.options.preventDefaultException
)
) {
click(e)
}
this.lastClickTime = dblclickTrigged ? null : getNow()
return true
}
return false
}
private handleEnd(e: TouchEvent) {
if (this.hooks.trigger(this.hooks.eventTypes.beforeEnd, e)) {
return
}
const currentPos = this.getCurrentPos()
this.scrollBehaviorX.updateDirection()
this.scrollBehaviorY.updateDirection()
if (this.hooks.trigger(this.hooks.eventTypes.end, e, currentPos)) {
return true
}
this.animater.translate(currentPos)
this.endTime = getNow()
const duration = this.endTime - this.startTime
this.hooks.trigger(this.hooks.eventTypes.scrollEnd, currentPos, duration)
}