Skip to content

Commit

Permalink
add workaround to filter redundant hammer touch event following mouse…
Browse files Browse the repository at this point in the history
… event on desktop chrome touchscreen; see hammerjs/hammer.js#1084 and related
  • Loading branch information
rhuehn committed Aug 26, 2017
1 parent aa9dd89 commit 09fcffb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ import {mixinEventEmitter} from '@theatersoft/bus'
const stack = [] // stack of sinks
let sink = {}

const filterTouchMouse = _touch => f => e => {
if (e.type === 'tap') {
if (_touch && e.gesture.pointerType === 'mouse') {
_touch = false
return
}
_touch = e.gesture.pointerType === 'touch'
}
f(e)
}

const focus = new (mixinEventEmitter(class {
constructor () {
Hammer(window.document.body, {
drag_lock_to_axis: true
})
.on("tap dragleft dragright dragend swipeleft swiperight", e => {
.on("tap dragleft dragright dragend swipeleft swiperight", filterTouchMouse()(e => {
if (sink.onGesture) sink.onGesture(e)
else if (sink.emit) sink.emit('gesture', e)
})
}))

document.onkeydown = e => {
if (e.keyCode === 8) {
Expand Down

0 comments on commit 09fcffb

Please sign in to comment.