ten1seven / what-input

A global utility for tracking the current input method (mouse/pointer, keyboard or touch).
https://ten1seven.github.io/what-input
MIT License
1.35k stars 89 forks source link

Compatibility with Chrome Emulation Mode #15

Closed solomonhawk closed 8 years ago

solomonhawk commented 8 years ago

When testing with Chrome Emulator mode set to iPhone(or other touch device), what-input fails to bind the touchstart event since 'ontouchstart' in document.documentElement is false. Instead we should be checking for 'ontouchstart' in window which is true in Chrome when Device Emulation is active via Modernizr.

http://stackoverflow.com/questions/28544445/how-to-detect-device-mode-emulation http://www.stucox.com/blog/you-cant-detect-a-touchscreen/

solomonhawk commented 8 years ago

@ten1seven do you know whether this change can/will break other functionality of what-input?

ten1seven commented 8 years ago

It shouldn't hurt anything at all. Are you proposing I replace this:

if ('ontouchstart' in document.documentElement) {

With the whole if from Modernizr?

if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {

Or just this?

if ('ontouchstart' in window) {