Env.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Env.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /**
  11. * This class contains various environment constants like browser versions etc.
  12. * Normally you don't want to sniff specific browser versions but sometimes you have
  13. * to when it's impossible to feature detect. So use this with care.
  14. *
  15. * @class tinymce.Env
  16. * @static
  17. */
  18. define("tinymce/Env", [], function() {
  19. var nav = navigator, userAgent = nav.userAgent;
  20. var opera, webkit, ie, ie11, gecko, mac, iDevice;
  21. opera = window.opera && window.opera.buildNumber;
  22. webkit = /WebKit/.test(userAgent);
  23. ie = !webkit && !opera && (/MSIE/gi).test(userAgent) && (/Explorer/gi).test(nav.appName);
  24. ie = ie && /MSIE (\w+)\./.exec(userAgent)[1];
  25. ie11 = userAgent.indexOf('Trident/') != -1 && (userAgent.indexOf('rv:') != -1 || nav.appName.indexOf('Netscape') != -1) ? 11 : false;
  26. ie = ie || ie11;
  27. gecko = !webkit && !ie11 && /Gecko/.test(userAgent);
  28. mac = userAgent.indexOf('Mac') != -1;
  29. iDevice = /(iPad|iPhone)/.test(userAgent);
  30. // Is a iPad/iPhone and not on iOS5 sniff the WebKit version since older iOS WebKit versions
  31. // says it has contentEditable support but there is no visible caret.
  32. var contentEditable = !iDevice || userAgent.match(/AppleWebKit\/(\d*)/)[1] >= 534;
  33. return {
  34. /**
  35. * Constant that is true if the browser is Opera.
  36. *
  37. * @property opera
  38. * @type Boolean
  39. * @final
  40. */
  41. opera: opera,
  42. /**
  43. * Constant that is true if the browser is WebKit (Safari/Chrome).
  44. *
  45. * @property webKit
  46. * @type Boolean
  47. * @final
  48. */
  49. webkit: webkit,
  50. /**
  51. * Constant that is more than zero if the browser is IE.
  52. *
  53. * @property ie
  54. * @type Boolean
  55. * @final
  56. */
  57. ie: ie,
  58. /**
  59. * Constant that is true if the browser is Gecko.
  60. *
  61. * @property gecko
  62. * @type Boolean
  63. * @final
  64. */
  65. gecko: gecko,
  66. /**
  67. * Constant that is true if the os is Mac OS.
  68. *
  69. * @property mac
  70. * @type Boolean
  71. * @final
  72. */
  73. mac: mac,
  74. /**
  75. * Constant that is true if the os is iOS.
  76. *
  77. * @property iOS
  78. * @type Boolean
  79. * @final
  80. */
  81. iOS: iDevice,
  82. /**
  83. * Constant that is true if the browser supports editing.
  84. *
  85. * @property contentEditable
  86. * @type Boolean
  87. * @final
  88. */
  89. contentEditable: contentEditable,
  90. /**
  91. * Transparent image data url.
  92. *
  93. * @property transparentSrc
  94. * @type Boolean
  95. * @final
  96. */
  97. transparentSrc: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
  98. /**
  99. * Returns true/false if the browser can or can't place the caret after a inline block like an image.
  100. *
  101. * @property noCaretAfter
  102. * @type Boolean
  103. * @final
  104. */
  105. caretAfter: ie != 8,
  106. /**
  107. * Constant that is true if the browser supports native DOM Ranges. IE 9+.
  108. *
  109. * @property range
  110. * @type Boolean
  111. */
  112. range: window.getSelection && "Range" in window,
  113. /**
  114. * Returns the IE document mode for non IE browsers this will fake IE 10.
  115. *
  116. * @property documentMode
  117. * @type Number
  118. */
  119. documentMode: ie ? (document.documentMode || 7) : 10
  120. };
  121. });