Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Tunnel source event preventDefault to PointerEvents
Browse files Browse the repository at this point in the history
- Only way to disable some default actions
- Related to #103
  • Loading branch information
dfreedm committed Nov 4, 2013
1 parent 3fa843d commit 2deb730
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
inEvent.relatedTarget = null;
}
var e = new PointerEvent(inType, inEvent);
e.preventDefault = inEvent.preventDefault;
this.targets.set(e, this.targets.get(inEvent) || inEvent.target);
return e;
},
Expand All @@ -244,6 +245,12 @@
p = CLONE_PROPS[i];
eventCopy[p] = inEvent[p] || CLONE_DEFAULTS[i];
}
// keep the semantics of preventDefault
if (inEvent.preventDefault) {
eventCopy.preventDefault = function() {
inEvent.preventDefault();
};
}
return eventCopy;
},
getTarget: function(inEvent) {
Expand Down
6 changes: 6 additions & 0 deletions src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
},
prepareEvent: function(inEvent) {
var e = dispatcher.cloneEvent(inEvent);
// forward mouse preventDefault
var pd = e.preventDefault;
e.preventDefault = function() {
inEvent.preventDefault();
pd();
};
e.pointerId = this.POINTER_ID;
e.isPrimary = true;
e.pointerType = this.POINTER_TYPE;
Expand Down
10 changes: 10 additions & 0 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@
processTouches: function(inEvent, inFunction) {
var tl = inEvent.changedTouches;
var pointers = touchMap(tl, this.touchToPointer, this);
// forward touch preventDefaults
pointers.forEach(function(p) {
var pd = p.preventDefault;
p.preventDefault = function() {
this.scrolling = false;
this.firstXY = null;
inEvent.preventDefault();
pd();
};
}, this);
pointers.forEach(inFunction, this);
},
// For single axis scrollers, determines whether the element should emit
Expand Down

0 comments on commit 2deb730

Please sign in to comment.