Skip to content

Commit

Permalink
Support preventDefault() on touch (#3693)
Browse files Browse the repository at this point in the history
* Support preventDefault() on touch

Expose setting to enable mouse handlers on touch-only devices

Fixes #3567

* remove experimental setting to disable touch-only detection
  • Loading branch information
dfreedm committed Jun 7, 2016
1 parent 6c0acef commit b9c874e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/standard/gestures.html
Expand Up @@ -391,10 +391,9 @@

// forward `preventDefault` in a clean way
if (ev.defaultPrevented) {
var se = detail.sourceEvent;
// sourceEvent may be a touch, which is not preventable this way
if (se && se.preventDefault) {
se.preventDefault();
var preventer = detail.preventer || detail.sourceEvent;
if (preventer && preventer.preventDefault) {
preventer.preventDefault();
}
}
},
Expand Down Expand Up @@ -461,16 +460,17 @@
this.fire('down', t, e);
},
touchstart: function(e) {
this.fire('down', Gestures.findOriginalTarget(e), e.changedTouches[0]);
this.fire('down', Gestures.findOriginalTarget(e), e.changedTouches[0], e);
},
touchend: function(e) {
this.fire('up', Gestures.findOriginalTarget(e), e.changedTouches[0]);
this.fire('up', Gestures.findOriginalTarget(e), e.changedTouches[0], e);
},
fire: function(type, target, event) {
fire: function(type, target, event, preventer) {
Gestures.fire(target, type, {
x: event.clientX,
y: event.clientY,
sourceEvent: event,
preventer: preventer,
prevent: function(e) {
return Gestures.prevent(e);
}
Expand Down Expand Up @@ -596,11 +596,11 @@
// reset started state on up
this.info.state = 'end';
this.info.addMove({x: ct.clientX, y: ct.clientY});
this.fire(t, ct);
this.fire(t, ct, e);
}
},

fire: function(target, touch) {
fire: function(target, touch, preventer) {
var secondlast = this.info.moves[this.info.moves.length - 2];
var lastmove = this.info.moves[this.info.moves.length - 1];
var dx = lastmove.x - this.info.x;
Expand All @@ -619,6 +619,7 @@
ddx: ddx,
ddy: ddy,
sourceEvent: touch,
preventer: preventer,
hover: function() {
return Gestures.deepTargetFind(touch.clientX, touch.clientY);
}
Expand Down Expand Up @@ -662,13 +663,13 @@
},

touchstart: function(e) {
this.save(e.changedTouches[0]);
this.save(e.changedTouches[0], e);
},
touchend: function(e) {
this.forward(e.changedTouches[0]);
this.forward(e.changedTouches[0], e);
},

forward: function(e) {
forward: function(e, preventer) {
var dx = Math.abs(e.clientX - this.info.x);
var dy = Math.abs(e.clientY - this.info.y);
var t = Gestures.findOriginalTarget(e);
Expand All @@ -679,7 +680,8 @@
Gestures.fire(t, 'tap', {
x: e.clientX,
y: e.clientY,
sourceEvent: e
sourceEvent: e,
preventer: preventer
});
}
}
Expand Down

0 comments on commit b9c874e

Please sign in to comment.