Skip to content

Instantly share code, notes, and snippets.

@yuka2py
Created October 6, 2014 23:56
Show Gist options
  • Save yuka2py/1cb7f695c0ec89b568e8 to your computer and use it in GitHub Desktop.
Save yuka2py/1cb7f695c0ec89b568e8 to your computer and use it in GitHub Desktop.
modernizr.environ.coffee
"use strict"
do ->
if !window.Modernizr
return
ua = new String(window.navigator.userAgent.toLowerCase())
ua.has = (cond) ->
@indexOf(cond) != -1
msie = ua.has('msie')
chrome = ua.has('chrome')
safari = ua.has('safari') && chrome
firefox = ua.has('firefox')
opera = ua.has('opera') || ua.has('opr/') #opera 15+
window.Modernizr.addTest {
'msie' : () ->
msie
'chrome' : () ->
chrome
'safari' : () ->
safari
'firefox' : () ->
firefox
'opera' : () ->
opera
}
iphone = ua.has('iphone')
ipod = ua.has('ipod')
ipad = ua.has('ipad')
macosx = ua.has('mac os x')
android = ua.has('android')
androidPhone = android && ua.has('mobile')
androidTablet = android && ! ua.has('mobile')
windows = ua.has('windows')
windowsPhone = windows && ua.has('phone')
windowsTablet = windows && ua.has('touch')
window.Modernizr.addTest {
'ios' : () ->
iphone || ipod || ipad
'iphone' : () ->
iphone
'ipod' : () ->
ipod
'ipad' : () ->
ipad
'macosx' : () ->
macosx
'android' : () ->
android
'androidPhone' : () ->
androidPhone
'androidTablet' : () ->
androidTablet
'windows' : () ->
windows
'windowsPhone' : () ->
windowsPhone
'windowsTablet' : () ->
windowsTablet
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment