Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. $ ->
  2. window.ua = {}
  3. ua = window.ua
  4.  
  5. ua.name = window.navigator.userAgent.toLowerCase()
  6.  
  7. ua.isiPhone = ua.name.indexOf("iphone") > -1
  8. ua.isiPod = ua.name.indexOf("ipod") > -1
  9. ua.isiPad = ua.name.indexOf("ipad") > -1
  10. ua.isiOS = ua.isiPhone or ua.isiPod or ua.isiPad
  11. ua.isAndroid = ua.name.indexOf("android") > -1
  12. ua.isTablet = ua.isiPad or (ua.isAndroid and ua.name.indexOf("mobile") < 0)
  13.  
  14. if ua.isiOS
  15. verArray = /(os)\s([0-9]{1,}[\_0-9]{1,})/.exec(ua.name)
  16. ua.ver = parseInt(verArray[2].replace(/\./g, ""), 10) if verArray
  17.  
  18. if ua.isAndroid
  19. verArray = /(android)\s([0-9]{1,}[\.0-9]{1,})/.exec(ua.name)
  20. ua.ver = parseInt(verArray[2].replace(/\./g, ""), 10) if verArray
  21.  
  22. if ua.isiPhone
  23. w = screen.width
  24. h = screen.height
  25. ua.iPhoneVer = if (w is 480 or h is 480) then "iPhone4" else if (w is 568 or h is 568) then "iPhone5" else if (w is 667 or h is 667) then "iPhone6" else if (w is 736 or h is 736) then "iPhone6plus" else "iPhone-unknown"
  26.  
  27. $("body")
  28. .addClass ->
  29. c = ""
  30. if ua.isiPhone
  31. c += "iPhone "
  32. c += "#{ua.iPhoneVer} "
  33. c += "iPod " if ua.isiPod
  34. c += "iPad " if ua.isiPad
  35. c += "iOS iOS_#{ua.ver} " if ua.isiOS
  36. c += "android android_#{ua.ver} " if ua.isAndroid
  37. c += "tablet" if ua.isTablet
  38. c
  39.  
  40. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement