Modernizr.touch detects touch events not touch devices #548
|
Yes, yes we should. Caniuse.com says Firefox 9+ supports touch but our test says otherwise when comparing to caniuse.com results. |
|
I think there is already way too much code around that expects |
|
I like dave's proposal. We tried capturing firefox touch in the see also jquery's upcoming blog post. |
|
Yes, I am afraid there are dark days ahead when it comes to apps handling touch events. The Webkit model would have been fine with me but it seems unlikely to gain a W3C blessing now. We can blame Apple's foot-dragging for this fragmentation. |
|
Yep this will be good to breakout touch into a plugin since it'll get huge testing for all variants. I'm pretty sure caniuse.com is wrong when it says firefox supports touch I have been poking around fennec and it doesn't support touch and they deprecated their |
|
ref #448 - I agree with the second point of optimizing the layout with media queries. Any sufficiently small screen can be handled with those. But in any case, windows phones currently don't send any events whatsoever (not even MSPointerEvents, they are slated for later versions), so you would need to detect that and render e.g. clickable controls vs swipeable ones. So for the current breed of windows phones, "touch" being true is valid in that the input method is a touch one and you need bigger manipulation controls for the user to hit. Then again, "touch" being false is valid in that the browser doesn't send any meaningful information whatsoever on the user's touch input. |
|
So there is
I think media queries tackle the second, for now... but so shall we just focus on touch event models? |
|
I agree that's a good strategy. Having Modernirz.touch return the applicable touch event model, and null/false if no touch event model is present should be enough cue to add non-touch manipulable controls on the page. |
|
Should that be Do we have an idea how people are using |
|
@dmethvin yeah very good point that's how a lot of people would be using it. Not sure how we could handle it, the docs clearly state that it will return true in situtations where it's not a touchscreen device but does support touch. |
|
Related: http://blogs.msdn.com/b/ie/archive/2012/07/12/ie10-user-agent-string-update.aspx includes msft's proposed feature detect |
|
Yikes, this is too complicated for me. Props to you all. |
|
Related: http://code.google.com/p/chromium/issues/detail?id=152149 worth reading:
|
|
Confirmation that the Chrome team added support for pointer and hover media queries to webkit and enabled Chromium to appropriately enable them when it discovers a touch screen. It's either now (or very soon) available in desktop Chrome (Windows 8 in particular), and Chrome for Android. It's worth pointing out some gotchas:
To avoid confusion, I expect us to deprecate |
|
As for pointer/hover media queries.. each WebKit port needs to enable them individually-- the embedding environment needs to inform webkit what hardware the device has.. As such, it's possible the next releases of Blackberry, Nokia, iOS, and other webkit ports may not have these media queries enabled yet. If you have friends there, make sure they know you want them. :) |
|
So would |
|
Modernizr.touchevents would be true if either w3c or pointer were and then the more detailed one would indicate which model(s) is/are coarsepointer probably needs its own detect, maybe named that On Mon, Jan 7, 2013 at 5:23 PM, Ryan Seddon notifications@github.comwrote:
|
|
Thanks for these updates @paulirish. Does it really make sense for a Wouldn't simply Hopefully Kinect-style motion sensing input devices would fire PointerEvents too, but by definition don't involve touching anything! Also, My opinion would be that Modernizr should stick to detecting static browser support for PointerEvents and TouchEvents, while media queries can be used to determine, dynamically, whether or not a certain input device capability is present. So no need for Encouraging this pattern would (eventually) mean browsers no longer have to enable/disable touch-related APIs at runtime based on the input devices connected, and would encourage developers to consider input modes as a dynamic feature, like we already do for screen size. I love the idea of opening a web page on a tablet at home, using a mouse & keyboard with it, unplugging it to head out the door and the UI automatically switching to a touch-friendly variant. |
|
I like everything you just said. On Tue, Jan 8, 2013 at 12:33 AM, Stu Cox notifications@github.com wrote:
|
Pointer choices should just be considered part of a responsive design. |
|
@stucox well said and I agree with everything. |
|
I agree with everything @stucox suggested as well. |
|
Slight problem with the plan above: we already have So... |
|
Or break more apis and move CSS pointer-events (to csspointerevents) Damn it. :( |
|
|
But seriously, i like re-purposing the name since I suspect it will be much more commonly used. Maybe we can lobby to get the CSS pointer events renamed. |
|
yeah ok probably not my best idea lets just make it bold in release notes that pointer-events means something else now. |
|
@stucox nope not yet. On Tue, Jan 29, 2013 at 3:26 AM, Stu Cox notifications@github.com wrote:
|
|
So what is the recommended way to detect touch now? |
|
You can't reliably. Alternative approaches depend on your use case — but this HTML5 Rocks article is well worth a read. |
|
After all that was said, you got to the bottom and used a vague term like "detect touch". You'll need to be more specific. Detect the potential for the device to generate WebKit touch events? Detect the ability to generate Microsoft pointer events? Detect a device capable of generating any sort of events when its screen is touched, without regard for how it's exposed in JavaScript? Detect a touch-capable device that (currently or eternally) has no other means of interaction such as a mouse or physical keyboard? The info in #869 may be helpful and #805 mentions the new |
|
Basically, any handheld device where the main input type is via a touch sensitive screen. Nathaniel Higgins On Wednesday, 27 March 2013 at 17:32, Dave Methvin wrote:
|
|
The details of the input mechanisms simply aren't currently made available to apps running in the browser. So "assume nothing" tends to be the best advice at the moment. As well as the HTML5 Rocks article, this is worth a read: http://globalmoxie.com/blog/desktop-touch-design.shtml. |
|
It of course depends on lot of cases, but I found handy the following checks (n addition to Modernizr) to force the no-touch beahvior: if {(
(window.location.host == 'apps.facebook.com') || // in the facebook app it's difficult to manage media queries (cause of the sidebar) so in desktop devices with touch screen it's tricky
(window.screen.width > 1279 && window.devicePixelRatio == 1) || // this number could be probably 1281, there are no so many mobile devices with more than 1280 and pixelRatio equal to 1 (i.e. retina displays are equal to 2...)
(window.screen.width > 1000 && window.innerWidth < (window.screen.width * .9)) || // this checks in the end if a user is using a resized browser window which is not common on mobile devices
(window.screen.width > 1000 && !this.browser.mobile) // this.browser.mobile is a custom check that can use for instance a common jquery plugin for browser detection
) {
// then add a class to html
$('html').addClass('force-no-touch');
}then in the css applying the .no-touch class (modernizr), together with the custom .force-no-touch class |
IE Mobile e.g. doesnt expose webkit touch events but is a touch device..
what exactly does
Modernizr.touchimply? We should agree so we can document it.