Skip to content

Commit fbe9fd7

Browse files
committed
TouchAction: Add support map for specific values of touch-action
Fixes #952 Closes #955
1 parent bd6b82e commit fbe9fd7

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/touchaction.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented
88
var TOUCH_ACTION_NONE = 'none';
99
var TOUCH_ACTION_PAN_X = 'pan-x';
1010
var TOUCH_ACTION_PAN_Y = 'pan-y';
11+
var TOUCH_ACTION_MAP = getTouchActionProps();
1112

1213
/**
1314
* Touch Action
@@ -32,7 +33,7 @@ TouchAction.prototype = {
3233
value = this.compute();
3334
}
3435

35-
if (NATIVE_TOUCH_ACTION && this.manager.element.style) {
36+
if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
3637
this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
3738
}
3839
this.actions = value.toLowerCase().trim();
@@ -64,11 +65,6 @@ TouchAction.prototype = {
6465
* @param {Object} input
6566
*/
6667
preventDefaults: function(input) {
67-
// not needed with native support for the touchAction property
68-
if (NATIVE_TOUCH_ACTION) {
69-
return;
70-
}
71-
7268
var srcEvent = input.srcEvent;
7369
var direction = input.offsetDirection;
7470

@@ -79,9 +75,9 @@ TouchAction.prototype = {
7975
}
8076

8177
var actions = this.actions;
82-
var hasNone = inStr(actions, TOUCH_ACTION_NONE);
83-
var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
84-
var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
78+
var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
79+
var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
80+
var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
8581

8682
if (hasNone) {
8783
//do not prevent defaults if this is a tap gesture
@@ -151,3 +147,18 @@ function cleanTouchActions(actions) {
151147

152148
return TOUCH_ACTION_AUTO;
153149
}
150+
151+
function getTouchActionProps() {
152+
if (!NATIVE_TOUCH_ACTION) {
153+
return false;
154+
}
155+
var touchMap = {};
156+
var cssSupports = window.CSS && window.CSS.supports;
157+
['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function(val) {
158+
159+
// If css.supports is not supported but there is native touch-action assume it supports
160+
// all values. This is the case for IE 10 and 11.
161+
touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true;
162+
});
163+
return touchMap;
164+
}

0 commit comments

Comments
 (0)