Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop trying to detect touch and mobile devices #1067

Open
david-mark opened this issue Jan 24, 2017 · 2 comments
Open

Stop trying to detect touch and mobile devices #1067

david-mark opened this issue Jan 24, 2017 · 2 comments

Comments

@david-mark
Copy link

david-mark commented Jan 24, 2017

There's absolutely no point in trying to pigeonhole devices as "touch", "touch only", etc. Not only impossible, but pointless (no puns intended). Proper pointer event handling makes no such assumptions and browser scripts should never reference the UA string.

const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;

const SUPPORT_TOUCH = ('ontouchstart' in window);
const SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined;
const SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);

Attach both touch and pointer listeners and deal with them in turn. No need to try to predict which will fire.

@grumpygary
Copy link

add:
delete window.PointerEvent;
in your index.html PRIOR to loading hammer.js, and it will ignore those events.
You can also set SUPPORT_POINTER_EVENTS = false; (line 384 of v2.0.8) to do the same thing.
Ideally the devs would add the ability to turn this off, but so goes the open source dilemma...

@david-mark
Copy link
Author

david-mark commented Apr 11, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants