Skip to content

Commit

Permalink
TouchAction: Add support map for specific values of touch-action
Browse files Browse the repository at this point in the history
Fixes #952
Closes #955
  • Loading branch information
arschmitz committed Apr 4, 2016
1 parent bd6b82e commit fbe9fd7
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/touchaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

0 comments on commit fbe9fd7

Please sign in to comment.