From 2deb730f221277ac421f632caf70f5394c5a6d94 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 4 Nov 2013 15:21:54 -0800 Subject: [PATCH] Tunnel source event preventDefault to PointerEvents - Only way to disable some default actions - Related to #103 --- src/dispatcher.js | 7 +++++++ src/mouse.js | 6 ++++++ src/touch.js | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/dispatcher.js b/src/dispatcher.js index 7d11d239..04da312a 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -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; }, @@ -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) { diff --git a/src/mouse.js b/src/mouse.js index e7138b7e..040d247e 100644 --- a/src/mouse.js +++ b/src/mouse.js @@ -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; diff --git a/src/touch.js b/src/touch.js index 24768ac3..8d461927 100644 --- a/src/touch.js +++ b/src/touch.js @@ -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