Skip to content

Commit 9d2e666

Browse files
author
Sebastien Pereira
committed
Add support for touch-action CSS when Pointer Events are not supported. Fixes #30.
1 parent 6154052 commit 9d2e666

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

events.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ define([
149149
if (has("mspointer")) {
150150
insertTouchActionCSSRule("-ms-touch-action");
151151
}
152+
// CSS rule to map CSS attribute in case user agent has native support for touch-action or -ms-touch-action
153+
// CSS property.
154+
if (has("touchAction")) {
155+
insertTouchActionCSSRule("touch-action");
156+
} else {
157+
// CSS rule for IE10 and IE11 preview
158+
if (has("msTouchAction")) {
159+
insertTouchActionCSSRule("-ms-touch-action");
160+
}
161+
}
152162

153163
/**
154164
* register click handler.

handlers/features.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ define([
99
has.add("mspointer", "onmspointerdown" in document); // UA supports Pointer Events (IE10+IE11 preview)
1010
has.add("chrome", /chrome/i.test(navigator.userAgent)); // UA is chrome.
1111
has.add("mobile", /(mobile)|(android)/i.test(navigator.userAgent)); // mobile device
12+
has.add("touchAction", "touchAction" in document.body.style);// touch-action CSS
13+
has.add("msTouchAction", "msTouchAction" in document.body.style);// -ms-touch-action CSS
1214
return has;
1315
});

handlers/touch.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* todo: pointerenter/pointerleave: generate on capture when target is the originated element.
66
*/
77
define([
8+
"./features",
89
"./touchTracker",
910
"./utils"
10-
], function (tracker, utils) {
11+
], function (has, tracker, utils) {
1112
"use strict";
1213

1314
var TouchEvents = {
@@ -127,8 +128,11 @@ define([
127128
utils.dispatchEvent(touchTarget, createPointer(utils.events.MOVE, e, touch, {}));
128129
}
129130
tracker.update(touch, e, touchTarget);
130-
// default actions must be prevented
131-
e.preventDefault();
131+
// touch default actions must be prevented.
132+
// Let user agent handle it if it supports the touch-action CSS property.
133+
if (!has("touchAction")) {
134+
e.preventDefault();
135+
}
132136
}
133137
}
134138
}

0 commit comments

Comments
 (0)