From 49fe2d03edc219cec0909dbbed695318603384ee Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Fri, 1 Aug 2014 13:54:00 -0700 Subject: [PATCH] Set default touch-action for certain gestures Fix sample to use correct event listener API --- samples/simple/index.html | 4 ++-- src/dispatcher.js | 9 ++++++++- src/track.js | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/samples/simple/index.html b/samples/simple/index.html index ea2ea94..a838836 100644 --- a/samples/simple/index.html +++ b/samples/simple/index.html @@ -66,7 +66,7 @@ -
+
@@ -97,7 +97,7 @@ } find('capture', 'output', 'enterleave'); events.forEach(function(en) { - PolymerGestures.addGesture(capture, en, function(inEvent) { + PolymerGestures.addEventListener(capture, en, function(inEvent) { appendOutput(inEvent.type + ' [' + inEvent.pointerId + ']'); inEvent.preventDefault(); }); diff --git a/src/dispatcher.js b/src/dispatcher.js index 2b9caf3..c973b2f 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -321,8 +321,8 @@ scope.activateGesture = function(node, gesture) { var dep = dispatcher.dependencyMap[gesture]; if (dep) { + var recognizer = dispatcher.gestures[dep.index]; if (dep.listeners === 0) { - var recognizer = dispatcher.gestures[dep.index]; if (recognizer) { recognizer.enabled = true; } @@ -332,6 +332,13 @@ dispatcher.register(node); node._pgListeners = 0; } + // TODO(dfreedm): re-evaluate bookkeeping to avoid using attributes + if (recognizer) { + var touchAction = recognizer.defaultActions && recognizer.defaultActions[gesture]; + if (touchAction && !node.hasAttribute('touch-action')) { + node.setAttribute('touch-action', touchAction); + } + } node._pgListeners++; } return Boolean(dep); diff --git a/src/track.js b/src/track.js index 86117b2..8a2827f 100644 --- a/src/track.js +++ b/src/track.js @@ -118,6 +118,9 @@ 'track', 'trackend' ], + defaultActions: { + 'track': 'none' + }, WIGGLE_THRESHOLD: 4, clampDir: function(inDelta) { return inDelta > 0 ? 1 : -1;