Skip to content

Instantly share code, notes, and snippets.

@NARKOZ
Created March 1, 2013 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NARKOZ/5064290 to your computer and use it in GitHub Desktop.
Save NARKOZ/5064290 to your computer and use it in GitHub Desktop.
# Restores `$.browser` functionality removed in jQuery 1.9
jQuery.uaMatch = (ua) ->
ua = ua.toLowerCase()
match = /(chrome)[ \/]([\w.]+)/.exec(ua) or
/(webkit)[ \/]([\w.]+)/.exec(ua) or
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) or
/(msie) ([\w.]+)/.exec(ua) or
ua.indexOf("compatible") < 0 and /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) or []
browser: match[1] or ''
version: match[2] or '0'
matched = jQuery.uaMatch(navigator.userAgent)
browser = {}
if matched.browser
browser[matched.browser] = true
browser.version = matched.version
if browser.chrome
browser.webkit = true
else if browser.webkit
browser.safari = true
jQuery.browser = browser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment