Skip to content

Commit

Permalink
feat(utils): add double touch event handler class
Browse files Browse the repository at this point in the history
  • Loading branch information
kslimani committed Apr 17, 2019
1 parent cfca744 commit cef0d2b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/base/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,32 @@ export class DomRecycler {

DomRecycler.options = { recycleVideo: false }

export class DoubleTouchEventHandler {
constructor(delay = 500) {
this.delay = delay
this.lastTime = 0
this.timer = null
}

handle(touchendEvent, cb) {
// Based on http://jsfiddle.net/brettwp/J4djY/
let currentTime = new Date().getTime()
let tapLength = currentTime - this.lastTime
clearTimeout(this.timer)

if (tapLength < this.delay && tapLength > 0) {
cb()
touchendEvent.preventDefault()
} else {
this.timer = setTimeout(() => {
clearTimeout(this.timer)
}, this.delay)
}

this.lastTime = currentTime
}
}

export default {
Config,
Fullscreen,
Expand All @@ -329,5 +355,6 @@ export default {
now,
removeArrayItem,
canAutoPlayMedia,
Media
Media,
DoubleTouchEventHandler
}

0 comments on commit cef0d2b

Please sign in to comment.