env.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or http://ckeditor.com/license
  4. */
  5. /**
  6. * @fileOverview Defines the {@link CKEDITOR.env} object which contains
  7. * environment and browser information.
  8. */
  9. if ( !CKEDITOR.env ) {
  10. /**
  11. * Environment and browser information.
  12. *
  13. * @class CKEDITOR.env
  14. * @singleton
  15. */
  16. CKEDITOR.env = ( function() {
  17. var agent = navigator.userAgent.toLowerCase(),
  18. edge = agent.match( /edge[ \/](\d+.?\d*)/ ),
  19. trident = agent.indexOf( 'trident/' ) > -1,
  20. ie = !!( edge || trident );
  21. var env = {
  22. /**
  23. * Indicates that CKEditor is running in Internet Explorer.
  24. *
  25. * if ( CKEDITOR.env.ie )
  26. * alert( 'I\'m running in IE!' );
  27. *
  28. * **Note:** This property is also set to `true` if CKEditor is running
  29. * in {@link #edge Microsoft Edge}.
  30. *
  31. * @property {Boolean}
  32. */
  33. ie: ie,
  34. /**
  35. * Indicates that CKEditor is running in Microsoft Edge.
  36. *
  37. * if ( CKEDITOR.env.edge )
  38. * alert( 'I\'m running in Edge!' );
  39. *
  40. * See also {@link #ie}.
  41. *
  42. * @since 4.5
  43. * @property {Boolean}
  44. */
  45. edge: !!edge,
  46. /**
  47. * Indicates that CKEditor is running in a WebKit-based browser, like Safari,
  48. * or Blink-based browser, like Chrome.
  49. *
  50. * if ( CKEDITOR.env.webkit )
  51. * alert( 'I\'m running in a WebKit browser!' );
  52. *
  53. * @property {Boolean}
  54. */
  55. webkit: !ie && ( agent.indexOf( ' applewebkit/' ) > -1 ),
  56. /**
  57. * Indicates that CKEditor is running in Adobe AIR.
  58. *
  59. * if ( CKEDITOR.env.air )
  60. * alert( 'I\'m on AIR!' );
  61. *
  62. * @property {Boolean}
  63. */
  64. air: ( agent.indexOf( ' adobeair/' ) > -1 ),
  65. /**
  66. * Indicates that CKEditor is running on Macintosh.
  67. *
  68. * if ( CKEDITOR.env.mac )
  69. * alert( 'I love apples!'' );
  70. *
  71. * @property {Boolean}
  72. */
  73. mac: ( agent.indexOf( 'macintosh' ) > -1 ),
  74. /**
  75. * Indicates that CKEditor is running in a Quirks Mode environment.
  76. *
  77. * if ( CKEDITOR.env.quirks )
  78. * alert( 'Nooooo!' );
  79. *
  80. * Internet Explorer 10 introduced the _New Quirks Mode_, which is similar to the _Quirks Mode_
  81. * implemented in other modern browsers and defined in the HTML5 specification. It can be handled
  82. * as the Standards mode, so the value of this property will be set to `false`.
  83. *
  84. * The _Internet Explorer 5 Quirks_ mode which is still available in Internet Explorer 10+
  85. * sets this value to `true` and {@link #version} to `7`.
  86. *
  87. * Read more: [IEBlog](http://blogs.msdn.com/b/ie/archive/2011/12/14/interoperable-html5-quirks-mode-in-ie10.aspx)
  88. *
  89. * @property {Boolean}
  90. */
  91. quirks: ( document.compatMode == 'BackCompat' && ( !document.documentMode || document.documentMode < 10 ) ),
  92. /**
  93. * Indicates that CKEditor is running in a mobile environemnt.
  94. *
  95. * if ( CKEDITOR.env.mobile )
  96. * alert( 'I\'m running with CKEditor today!' );
  97. *
  98. * @property {Boolean}
  99. */
  100. mobile: ( agent.indexOf( 'mobile' ) > -1 ),
  101. /**
  102. * Indicates that CKEditor is running on Apple iPhone/iPad/iPod devices.
  103. *
  104. * if ( CKEDITOR.env.iOS )
  105. * alert( 'I like little apples!' );
  106. *
  107. * @property {Boolean}
  108. */
  109. iOS: /(ipad|iphone|ipod)/.test( agent ),
  110. /**
  111. * Indicates that the browser has a custom domain enabled. This has
  112. * been set with `document.domain`.
  113. *
  114. * if ( CKEDITOR.env.isCustomDomain() )
  115. * alert( 'I\'m in a custom domain!' );
  116. *
  117. * @returns {Boolean} `true` if a custom domain is enabled.
  118. * @deprecated
  119. */
  120. isCustomDomain: function() {
  121. if ( !this.ie )
  122. return false;
  123. var domain = document.domain,
  124. hostname = window.location.hostname;
  125. return domain != hostname && domain != ( '[' + hostname + ']' ); // IPv6 IP support (#5434)
  126. },
  127. /**
  128. * Indicates that the page is running under an encrypted connection.
  129. *
  130. * if ( CKEDITOR.env.secure )
  131. * alert( 'I\'m on SSL!' );
  132. *
  133. * @returns {Boolean} `true` if the page has an encrypted connection.
  134. */
  135. secure: location.protocol == 'https:'
  136. };
  137. /**
  138. * Indicates that CKEditor is running in a Gecko-based browser, like
  139. * Firefox.
  140. *
  141. * if ( CKEDITOR.env.gecko )
  142. * alert( 'I\'m riding a gecko!' );
  143. *
  144. * @property {Boolean}
  145. */
  146. env.gecko = ( navigator.product == 'Gecko' && !env.webkit && !env.ie );
  147. /**
  148. * Indicates that CKEditor is running in a Blink-based browser like Chrome.
  149. *
  150. * if ( CKEDITOR.env.chrome )
  151. * alert( 'I\'m running in Chrome!' );
  152. *
  153. * @property {Boolean} chrome
  154. */
  155. /**
  156. * Indicates that CKEditor is running in Safari (including the mobile version).
  157. *
  158. * if ( CKEDITOR.env.safari )
  159. * alert( 'I\'m on Safari!' );
  160. *
  161. * @property {Boolean} safari
  162. */
  163. if ( env.webkit ) {
  164. if ( agent.indexOf( 'chrome' ) > -1 )
  165. env.chrome = true;
  166. else
  167. env.safari = true;
  168. }
  169. var version = 0;
  170. // Internet Explorer 6.0+
  171. if ( env.ie ) {
  172. // We use env.version for feature detection, so set it properly.
  173. if ( edge ) {
  174. version = parseFloat( edge[ 1 ] );
  175. } else if ( env.quirks || !document.documentMode ) {
  176. version = parseFloat( agent.match( /msie (\d+)/ )[ 1 ] );
  177. } else {
  178. version = document.documentMode;
  179. }
  180. // Deprecated features available just for backwards compatibility.
  181. env.ie9Compat = version == 9;
  182. env.ie8Compat = version == 8;
  183. env.ie7Compat = version == 7;
  184. env.ie6Compat = version < 7 || env.quirks;
  185. /**
  186. * Indicates that CKEditor is running in an IE6-like environment, which
  187. * includes IE6 itself as well as IE7, IE8 and IE9 in Quirks Mode.
  188. *
  189. * @deprecated
  190. * @property {Boolean} ie6Compat
  191. */
  192. /**
  193. * Indicates that CKEditor is running in an IE7-like environment, which
  194. * includes IE7 itself and IE8's IE7 Document Mode.
  195. *
  196. * @deprecated
  197. * @property {Boolean} ie7Compat
  198. */
  199. /**
  200. * Indicates that CKEditor is running in Internet Explorer 8 on
  201. * Standards Mode.
  202. *
  203. * @deprecated
  204. * @property {Boolean} ie8Compat
  205. */
  206. /**
  207. * Indicates that CKEditor is running in Internet Explorer 9 on
  208. * Standards Mode.
  209. *
  210. * @deprecated
  211. * @property {Boolean} ie9Compat
  212. */
  213. }
  214. // Gecko.
  215. if ( env.gecko ) {
  216. var geckoRelease = agent.match( /rv:([\d\.]+)/ );
  217. if ( geckoRelease ) {
  218. geckoRelease = geckoRelease[ 1 ].split( '.' );
  219. version = geckoRelease[ 0 ] * 10000 + ( geckoRelease[ 1 ] || 0 ) * 100 + ( geckoRelease[ 2 ] || 0 ) * 1;
  220. }
  221. }
  222. // Adobe AIR 1.0+
  223. // Checked before Safari because AIR have the WebKit rich text editor
  224. // features from Safari 3.0.4, but the version reported is 420.
  225. if ( env.air )
  226. version = parseFloat( agent.match( / adobeair\/(\d+)/ )[ 1 ] );
  227. // WebKit 522+ (Safari 3+)
  228. if ( env.webkit )
  229. version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[ 1 ] );
  230. /**
  231. * Contains the browser version.
  232. *
  233. * For Gecko-based browsers (like Firefox) it contains the revision
  234. * number with first three parts concatenated with a padding zero
  235. * (e.g. for revision 1.9.0.2 we have 10900).
  236. *
  237. * For WebKit-based browsers (like Safari and Chrome) it contains the
  238. * WebKit build version (e.g. 522).
  239. *
  240. * For IE browsers, it matches the "Document Mode".
  241. *
  242. * if ( CKEDITOR.env.ie && CKEDITOR.env.version <= 6 )
  243. * alert( 'Ouch!' );
  244. *
  245. * @property {Number}
  246. */
  247. env.version = version;
  248. /**
  249. * Since CKEditor 4.5 this property is a blacklist of browsers incompatible with CKEditor. It means that it is
  250. * set to `false` only in browsers that are known to be incompatible. Before CKEditor 4.5 this
  251. * property was a whitelist of browsers that were known to be compatible with CKEditor.
  252. *
  253. * The reason for this change is the rising fragmentation of the browser market (especially the mobile segment).
  254. * It became too complicated to check in which new environments CKEditor is going to work.
  255. *
  256. * In order to enable CKEditor 4.4.x and below in unsupported environments see the
  257. * [Enabling CKEditor in Unsupported Environments](#!/guide/dev_unsupported_environments) article.
  258. *
  259. * if ( CKEDITOR.env.isCompatible )
  260. * alert( 'Your browser is not known to be incompatible with CKEditor!' );
  261. *
  262. * @property {Boolean}
  263. */
  264. env.isCompatible =
  265. // IE 7+ (IE 7 is not supported, but IE Compat Mode is and it is recognized as IE7).
  266. !( env.ie && version < 7 ) &&
  267. // Firefox 4.0+.
  268. !( env.gecko && version < 40000 ) &&
  269. // Chrome 6+, Safari 5.1+, iOS 5+.
  270. !( env.webkit && version < 534 );
  271. /**
  272. * Indicates that CKEditor is running in the HiDPI environment.
  273. *
  274. * if ( CKEDITOR.env.hidpi )
  275. * alert( 'You are using a screen with high pixel density.' );
  276. *
  277. * @property {Boolean}
  278. */
  279. env.hidpi = window.devicePixelRatio >= 2;
  280. /**
  281. * Indicates that CKEditor is running in a browser which uses a bogus
  282. * `<br>` filler in order to correctly display caret in empty blocks.
  283. *
  284. * @since 4.3
  285. * @property {Boolean}
  286. */
  287. env.needsBrFiller = env.gecko || env.webkit || ( env.ie && version > 10 );
  288. /**
  289. * Indicates that CKEditor is running in a browser which needs a
  290. * non-breaking space filler in order to correctly display caret in empty blocks.
  291. *
  292. * @since 4.3
  293. * @property {Boolean}
  294. */
  295. env.needsNbspFiller = env.ie && version < 11;
  296. /**
  297. * A CSS class that denotes the browser where CKEditor runs and is appended
  298. * to the HTML element that contains the editor. It makes it easier to apply
  299. * browser-specific styles to editor instances.
  300. *
  301. * myDiv.className = CKEDITOR.env.cssClass;
  302. *
  303. * @property {String}
  304. */
  305. env.cssClass = 'cke_browser_' + ( env.ie ? 'ie' : env.gecko ? 'gecko' : env.webkit ? 'webkit' : 'unknown' );
  306. if ( env.quirks )
  307. env.cssClass += ' cke_browser_quirks';
  308. if ( env.ie )
  309. env.cssClass += ' cke_browser_ie' + ( env.quirks ? '6 cke_browser_iequirks' : env.version );
  310. if ( env.air )
  311. env.cssClass += ' cke_browser_air';
  312. if ( env.iOS )
  313. env.cssClass += ' cke_browser_ios';
  314. if ( env.hidpi )
  315. env.cssClass += ' cke_hidpi';
  316. return env;
  317. } )();
  318. }
  319. // PACKAGER_RENAME( CKEDITOR.env )
  320. // PACKAGER_RENAME( CKEDITOR.env.ie )