I want a single site that uses the same HTML but "widgetizes" it in the best way for the platform it's served to.
Is there a standard practice for feature detecting mobile devices / hardware keyboards on the client and deciding whether to load jQuery Mobile along with the site's mobile JavaScript or jQuery UI and a script for a desktop experience?
The following seems like a reasonable way to do it but I wonder if Modernizr.touch is the best way to detect this? e.g.: Forcing touch might not be the best solution for Surface. Is there any way to detect if there's also a hardware keyboard?
Modernizr.load({
test: Modernizr.touch,
yep : ['jquery-mobile.js','mobile.js']
nope: ['jquery-ui.js','desktop.js']
});
Edit:
Found some relevant Modernizr bugs:
- Modernizr.touch detects touch events not touch devices
- IE10 "metro" is not detected as a touch capable device
I guess what I really need is a way to detect both whether the device is capable of touch and if it has a hardware keyboard. I could use David Mulder's answer for detecting device width in physical units (inches) as a proxy for that and assume anything > 11 inches has a keyboard, but I bet there's a massive tablet out there (or Google will release a nexus 12 tablet :) where that would make a wrong assumption.