PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/autobahn/useragent.js

http://github.com/tavendo/AutobahnJS
JavaScript | 105 lines | 82 code | 12 blank | 11 comment | 46 complexity | 9cb8c35cf095af165565f9f6b49d7631 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0
  1. ab._UA_FIREFOX = new RegExp(".*Firefox/([0-9+]*).*")
  2. ab._UA_CHROME = new RegExp(".*Chrome/([0-9+]*).*")
  3. ab._UA_CHROMEFRAME = new RegExp(".*chromeframe/([0-9]*).*")
  4. ab._UA_WEBKIT = new RegExp(".*AppleWebKit/([0-9+\.]*)\w*.*")
  5. ab._UA_WEBOS = new RegExp(".*webOS/([0-9+\.]*)\w*.*")
  6. ab._matchRegex = function(s, r) {
  7. var m = r.exec(s)
  8. if (m) return m[1]
  9. return m
  10. };
  11. ab.lookupWsSupport = function() {
  12. var ua = navigator.userAgent;
  13. // Internet Explorer
  14. if (ua.indexOf("MSIE") > -1) {
  15. if (ua.indexOf("MSIE 10") > -1)
  16. return [true,true,true]
  17. if (ua.indexOf("chromeframe") > -1) {
  18. var v = parseInt(ab._matchRegex(ua, ab._UA_CHROMEFRAME))
  19. if (v >= 14)
  20. return [true,false,true]
  21. return [false,false,false]
  22. }
  23. if (ua.indexOf("MSIE 8") > -1 || ua.indexOf("MSIE 9") > -1)
  24. return [true,true,true]
  25. return [false,false,false]
  26. }
  27. // Firefox
  28. else if (ua.indexOf("Firefox") > -1) {
  29. var v = parseInt(ab._matchRegex(ua, ab._UA_FIREFOX))
  30. if (v) {
  31. if (v >= 7)
  32. return [true,false,true]
  33. if (v >= 3)
  34. return [true,true,true]
  35. return [false,false,true]
  36. }
  37. return [false,false,true]
  38. }
  39. // Safari
  40. else if (ua.indexOf("Safari") > -1 && ua.indexOf("Chrome") == -1) {
  41. var v = ab._matchRegex(ua, ab._UA_WEBKIT)
  42. if (v) {
  43. if (ua.indexOf("Windows") > -1 && v == "534+") // Not sure about this test ~RMH
  44. return [true,false,true]
  45. if (ua.indexOf("Macintosh") > -1) {
  46. v = v.replace("+","").split(".")
  47. if ((parseInt(v[0]) == 535 && parseInt(v[1]) >= 24) || parseInt(v[0]) > 535)
  48. return [true,false,true]
  49. }
  50. if (ua.indexOf("webOS") > -1) {
  51. v = ab._matchRegex(ua, ab._UA_WEBOS).split(".")
  52. if (parseInt(v[0]) == 2)
  53. return [false,true,true]
  54. return [false,false,false]
  55. }
  56. return [true,true,true]
  57. }
  58. return [false,false,false]
  59. }
  60. // Chrome
  61. else if (ua.indexOf("Chrome") > -1) {
  62. var v = parseInt(ab._matchRegex(ua, ab._UA_CHROME))
  63. if (v) {
  64. if (v >= 14)
  65. return [true,false,true]
  66. if (v >= 4)
  67. return [true,true,true]
  68. return [false,false,true]
  69. }
  70. return [false,false,false]
  71. }
  72. // Android
  73. else if (ua.indexOf("Android") > -1) {
  74. // Firefox Mobile
  75. if (ua.indexOf("Firefox") > -1)
  76. return [true,false,true]
  77. // Chrome for Android
  78. else if (ua.indexOf("CrMo") > -1)
  79. return [true,false,true]
  80. // Opera Mobile
  81. else if (ua.indexOf("Opera") > -1)
  82. return [false,false,true]
  83. // Android Browser
  84. else if (ua.indexOf("CrMo") > -1)
  85. return [true,true,true]
  86. return [false,false,false]
  87. }
  88. // iOS
  89. else if (ua.indexOf("iPhone") > -1 || ua.indexOf("iPad") > -1 || ua.indexOf("iPod") > -1)
  90. return [false,false,true]
  91. // Unidentified
  92. return [false,false,false]
  93. };