Skip to content

Commit

Permalink
Fix initialization when dpointer loaded before document.body exists.
Browse files Browse the repository at this point in the history
Remove vestigial code for "-ms-touch-action" (IE10 is no longer supported).
Fix harmless (but useless) double-creation of CSS rule, refs #30.
Fix has("touch-device") to be true on iPad with iOS 13.

Note though that iOS and Mac now finally support pointer events
natively, so this library has mostly outlived its usefulness.
  • Loading branch information
wkeese committed Feb 13, 2020
1 parent 7811284 commit 9b49930
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This project proposes a unified and consistent javascript events API which aims
This API is a shim of the [W3C Pointer Events specification][W3C_pointer] and adds features that are out of scope of the current specification.

- Generates **Pointer Events** according to the current specification.
- Use attribute `touch-action` to set touch action on HTML elements; generates `touch-action` and `ms-touch-action` CSS properties when supported by the browser.
- Use attribute `touch-action` to set touch action on HTML elements; generates `touch-action` CSS properties when supported by the browser.
- Support **Pointer Capture** with mouse and touch events.
- Normalize **click** (Tap) events, **double click** (double Tap) events, and event **button/buttons/which** values.
- Supports immediate clicks (no ~300ms delay)
Expand Down
16 changes: 3 additions & 13 deletions events.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,12 @@ define([
document.head.insertBefore(styleElement, document.head.firstChild);
}

// CSS rule when user agent implements W3C Pointer Events or when a polyfill is in place.
if (has("pointer-events")) {
// CSS rule when user agent implements W3C Pointer Events or when a polyfill is in place,
// or user agent has native support for touch-action.
if (has("pointer-events") || has("css-touch-action")) {
insertTouchActionCSSRule("touch-action");
}

// CSS rule to map CSS attribute in case user agent has native support for touch-action or -ms-touch-action
// CSS property.
if (has("css-touch-action")) {
insertTouchActionCSSRule("touch-action");
} else {
// CSS rule for IE10 and IE11 preview
if (has("css-ms-touch-action")) {
insertTouchActionCSSRule("-ms-touch-action");
}
}

// start listening to native events
pointerEvents.enable();

Expand Down
13 changes: 9 additions & 4 deletions handlers/features.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/**
*
* Feature detection tests.
*/
define([
"requirejs-dplugins/has"
], function (has) {
if (typeof document !== "undefined") {
has.add("touch-events", "ontouchstart" in document); // UA supports Touch Events
has.add("pointer-events", "onpointerdown" in document); // UA supports Pointer Events
has.add("touch-device", /(mobile)|(android)/i.test(navigator.userAgent)); // mobile device
has.add("css-touch-action", "touchAction" in document.body.style);// touch-action CSS
has.add("css-ms-touch-action", "msTouchAction" in document.body.style);// -ms-touch-action CSS

// Mobile device
// Special test for iOS 13.1+, to counteract misleading userAgent string.
var ios13 = /Safari/.test(navigator.userAgent) && "ontouchstart" in document;
has.add("touch-device", /(mobile)|(android)/i.test(navigator.userAgent) || ios13); // mobile device

has.add("css-touch-action", "touchAction" in document.createElement("div").style);
}

return has;
});

0 comments on commit 9b49930

Please sign in to comment.