Created
January 9, 2014 22:05
-
-
Save grok/8342937 to your computer and use it in GitHub Desktop.
Requires: //cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.min.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var device = { | |
touch: false, | |
mobile: false, | |
over: '', | |
out: '', | |
retina: false, | |
transitions: false, | |
android: false | |
}; | |
function registerDevice() { | |
var suffix = '@2x'; | |
var density = (window.devicePixelRatio === undefined) ? 1 : window.devicePixelRatio; | |
if (density > 1) { | |
$('body').addClass('retina'); | |
device.retina = true; | |
} | |
device.transitions = Modernizr.csstransitions; | |
device.transforms = Modernizr.csstransforms; | |
device.transforms3d = Modernizr.csstransforms3d; | |
device.animations = Modernizr.cssanimations; | |
if ((navigator.userAgent.toLowerCase().indexOf('android') != -1)) device.android = true; | |
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('BlackBerry') != -1) || (navigator.userAgent.indexOf('Windows Phone') != -1) || (navigator.userAgent.toLowerCase().indexOf('android') != -1) && (navigator.userAgent.toLowerCase().indexOf('mobile') != -1)) { | |
$('body').addClass('mobile'); | |
device.mobile = true; | |
} | |
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('BlackBerry') != -1) || (navigator.userAgent.indexOf('Windows Phone') != -1) || (navigator.userAgent.toLowerCase().indexOf('android') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) { | |
$('body').addClass('touchscreen'); | |
device.touch = true; | |
} | |
if (device.touch) { | |
device.over = window.navigator.msPointerEnabled ? "MSPointerDown" : "touchstart"; | |
device.out = window.navigator.msPointerEnabled ? "MSPointerUp" : "touchend"; | |
device.instaClick = window.navigator.msPointerEnabled ? "MSPointerDown" : "touchstart"; | |
} else { | |
device.over = 'mouseenter'; | |
device.out = 'mouseleave'; | |
device.instaClick = 'click' | |
} | |
if (!device.touch) $('body').addClass('desktop'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment