From fbe9fd775fe8cb3d43faa9428bfa56b61b16edc7 Mon Sep 17 00:00:00 2001 From: Alexander Schmitz Date: Sun, 3 Apr 2016 22:38:48 -0400 Subject: [PATCH] TouchAction: Add support map for specific values of touch-action Fixes #952 Closes #955 --- src/touchaction.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/touchaction.js b/src/touchaction.js index 93a0bc4d2..55609012b 100644 --- a/src/touchaction.js +++ b/src/touchaction.js @@ -8,6 +8,7 @@ var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented var TOUCH_ACTION_NONE = 'none'; var TOUCH_ACTION_PAN_X = 'pan-x'; var TOUCH_ACTION_PAN_Y = 'pan-y'; +var TOUCH_ACTION_MAP = getTouchActionProps(); /** * Touch Action @@ -32,7 +33,7 @@ TouchAction.prototype = { value = this.compute(); } - if (NATIVE_TOUCH_ACTION && this.manager.element.style) { + if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) { this.manager.element.style[PREFIXED_TOUCH_ACTION] = value; } this.actions = value.toLowerCase().trim(); @@ -64,11 +65,6 @@ TouchAction.prototype = { * @param {Object} input */ preventDefaults: function(input) { - // not needed with native support for the touchAction property - if (NATIVE_TOUCH_ACTION) { - return; - } - var srcEvent = input.srcEvent; var direction = input.offsetDirection; @@ -79,9 +75,9 @@ TouchAction.prototype = { } var actions = this.actions; - var hasNone = inStr(actions, TOUCH_ACTION_NONE); - var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y); - var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X); + var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE]; + var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y]; + var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X]; if (hasNone) { //do not prevent defaults if this is a tap gesture @@ -151,3 +147,18 @@ function cleanTouchActions(actions) { return TOUCH_ACTION_AUTO; } + +function getTouchActionProps() { + if (!NATIVE_TOUCH_ACTION) { + return false; + } + var touchMap = {}; + var cssSupports = window.CSS && window.CSS.supports; + ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function(val) { + + // If css.supports is not supported but there is native touch-action assume it supports + // all values. This is the case for IE 10 and 11. + touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true; + }); + return touchMap; +}