Created
January 1, 2013 06:56
-
-
Save bfricka/4425653 to your computer and use it in GitHub Desktop.
Simple User Agent
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
### | |
Adapted from jqMobi (appMobi) | |
https://github.com/appMobi/jQ.Mobi | |
MIT License | |
### | |
window.UserAgent = -> | |
self = @ | |
self.ua = navigator.userAgent | |
self.os = {} | |
detectUA = (ua) -> | |
self.os.webkit = (if ua.match(/WebKit\/([\d.]+)/) then true else false) | |
self.os.android = (if ua.match(/(Android)\s+([\d.]+)/) or ua.match(/Silk-Accelerated/) then true else false) | |
self.os.androidICS = (if self.os.android and ua.match(/(Android)\s4/) then true else false) | |
self.os.ipad = (if ua.match(/(iPad).*OS\s([\d_]+)/) then true else false) | |
self.os.iphone = (if not self.os.ipad and ua.match(/(iPhone\sOS)\s([\d_]+)/) then true else false) | |
self.os.webos = (if ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/) then true else false) | |
self.os.touchpad = (if self.os.webos and ua.match(/TouchPad/) then true else false) | |
self.os.ios = self.os.ipad or self.os.iphone | |
self.os.ios6 = (if self.os.ios and ua.match(/(OS)\s([6])/) then true else false) | |
self.os.playbook = (if ua.match(/PlayBook/) then true else false) | |
self.os.blackberry = (if self.os.playbook or ua.match(/BlackBerry/) then true else false) | |
self.os.blackberry10 = (if self.os.blackberry and ua.match(/Safari\/536/) then true else false) | |
self.os.chrome = (if ua.match(/Chrome/) then true else false) | |
self.os.opera = (if ua.match(/Opera Mobi/) then true else false) | |
self.os.fennec = (if ua.match(/fennec/i) then true else false) | |
self.os.supportsTouch = Modernizr.touch | |
self.os.desktop = not (self.os.ios or self.os.android or self.os.blackberry or self.os.opera or self.os.fennec or self.os.supportsTouch) | |
detectUA(self.ua) | |
self.os |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment