env.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. /**
  6. * @fileOverview Defines the {@link CKEDITOR.env} object, which constains
  7. * environment and browser information.
  8. */
  9. if ( !CKEDITOR.env )
  10. {
  11. /**
  12. * @namespace Environment and browser information.
  13. */
  14. CKEDITOR.env = (function()
  15. {
  16. var agent = navigator.userAgent.toLowerCase();
  17. var opera = window.opera;
  18. var env =
  19. /** @lends CKEDITOR.env */
  20. {
  21. /**
  22. * Indicates that CKEditor is running on Internet Explorer.
  23. * @type Boolean
  24. * @example
  25. * if ( CKEDITOR.env.ie )
  26. * alert( "I'm on IE!" );
  27. */
  28. ie : /*@cc_on!@*/false,
  29. /**
  30. * Indicates that CKEditor is running on Opera.
  31. * @type Boolean
  32. * @example
  33. * if ( CKEDITOR.env.opera )
  34. * alert( "I'm on Opera!" );
  35. */
  36. opera : ( !!opera && opera.version ),
  37. /**
  38. * Indicates that CKEditor is running on a WebKit based browser, like
  39. * Safari.
  40. * @type Boolean
  41. * @example
  42. * if ( CKEDITOR.env.webkit )
  43. * alert( "I'm on WebKit!" );
  44. */
  45. webkit : ( agent.indexOf( ' applewebkit/' ) > -1 ),
  46. /**
  47. * Indicates that CKEditor is running on Adobe AIR.
  48. * @type Boolean
  49. * @example
  50. * if ( CKEDITOR.env.air )
  51. * alert( "I'm on AIR!" );
  52. */
  53. air : ( agent.indexOf( ' adobeair/' ) > -1 ),
  54. /**
  55. * Indicates that CKEditor is running on Macintosh.
  56. * @type Boolean
  57. * @example
  58. * if ( CKEDITOR.env.mac )
  59. * alert( "I love apples!" );
  60. */
  61. mac : ( agent.indexOf( 'macintosh' ) > -1 ),
  62. /**
  63. * Indicates that CKEditor is running on a quirks mode environemnt.
  64. * @type Boolean
  65. * @example
  66. * if ( CKEDITOR.env.quirks )
  67. * alert( "Nooooo!" );
  68. */
  69. quirks : ( document.compatMode == 'BackCompat' ),
  70. /**
  71. * Indicates that CKEditor is running on a mobile like environemnt.
  72. * @type Boolean
  73. * @example
  74. * if ( CKEDITOR.env.mobile )
  75. * alert( "I'm running with CKEditor today!" );
  76. */
  77. mobile : ( agent.indexOf( 'mobile' ) > -1 ),
  78. /**
  79. * Indicates that CKEditor is running on Apple iPhone/iPad/iPod devices.
  80. * @type Boolean
  81. * @example
  82. * if ( CKEDITOR.env.iOS )
  83. * alert( "I like little apples!" );
  84. */
  85. iOS : /(ipad|iphone|ipod)/.test(agent),
  86. /**
  87. * Indicates that the browser has a custom domain enabled. This has
  88. * been set with "document.domain".
  89. * @returns {Boolean} "true" if a custom domain is enabled.
  90. * @example
  91. * if ( CKEDITOR.env.isCustomDomain() )
  92. * alert( "I'm in a custom domain!" );
  93. */
  94. isCustomDomain : function()
  95. {
  96. if ( !this.ie )
  97. return false;
  98. var domain = document.domain,
  99. hostname = window.location.hostname;
  100. return domain != hostname &&
  101. domain != ( '[' + hostname + ']' ); // IPv6 IP support (#5434)
  102. },
  103. /**
  104. * Indicates that page is running under an encrypted connection.
  105. * @returns {Boolean} "true" if the page has an encrypted connection.
  106. * @example
  107. * if ( CKEDITOR.env.secure )
  108. * alert( "I'm in SSL!" );
  109. */
  110. secure : location.protocol == 'https:'
  111. };
  112. /**
  113. * Indicates that CKEditor is running on a Gecko based browser, like
  114. * Firefox.
  115. * @name CKEDITOR.env.gecko
  116. * @type Boolean
  117. * @example
  118. * if ( CKEDITOR.env.gecko )
  119. * alert( "I'm riding a gecko!" );
  120. */
  121. env.gecko = ( navigator.product == 'Gecko' && !env.webkit && !env.opera );
  122. var version = 0;
  123. // Internet Explorer 6.0+
  124. if ( env.ie )
  125. {
  126. version = parseFloat( agent.match( /msie (\d+)/ )[1] );
  127. /**
  128. * Indicates that CKEditor is running on Internet Explorer 8.
  129. * @name CKEDITOR.env.ie8
  130. * @type Boolean
  131. * @example
  132. * if ( CKEDITOR.env.ie8 )
  133. * alert( "I'm on IE8!" );
  134. */
  135. env.ie8 = !!document.documentMode;
  136. /**
  137. * Indicates that CKEditor is running on Internet Explorer 8 on
  138. * standards mode.
  139. * @name CKEDITOR.env.ie8Compat
  140. * @type Boolean
  141. * @example
  142. * if ( CKEDITOR.env.ie8Compat )
  143. * alert( "Now I'm on IE8, for real!" );
  144. */
  145. env.ie8Compat = document.documentMode == 8;
  146. /**
  147. * Indicates that CKEditor is running on Internet Explorer 9's standards mode.
  148. * @name CKEDITOR.env.ie9Compat
  149. * @type Boolean
  150. * @example
  151. * if ( CKEDITOR.env.ie9Compat )
  152. * alert( "IE9, the beauty of the web!" );
  153. */
  154. env.ie9Compat = document.documentMode == 9;
  155. /**
  156. * Indicates that CKEditor is running on an IE7-like environment, which
  157. * includes IE7 itself and IE8's IE7 document mode.
  158. * @name CKEDITOR.env.ie7Compat
  159. * @type Boolean
  160. * @example
  161. * if ( CKEDITOR.env.ie8Compat )
  162. * alert( "I'm on IE7 or on an IE7 like IE8!" );
  163. */
  164. env.ie7Compat = ( ( version == 7 && !document.documentMode )
  165. || document.documentMode == 7 );
  166. /**
  167. * Indicates that CKEditor is running on an IE6-like environment, which
  168. * includes IE6 itself and IE7 and IE8 quirks mode.
  169. * @name CKEDITOR.env.ie6Compat
  170. * @type Boolean
  171. * @example
  172. * if ( CKEDITOR.env.ie6Compat )
  173. * alert( "I'm on IE6 or quirks mode!" );
  174. */
  175. env.ie6Compat = ( version < 7 || env.quirks );
  176. }
  177. // Gecko.
  178. if ( env.gecko )
  179. {
  180. var geckoRelease = agent.match( /rv:([\d\.]+)/ );
  181. if ( geckoRelease )
  182. {
  183. geckoRelease = geckoRelease[1].split( '.' );
  184. version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1;
  185. }
  186. }
  187. // Opera 9.50+
  188. if ( env.opera )
  189. version = parseFloat( opera.version() );
  190. // Adobe AIR 1.0+
  191. // Checked before Safari because AIR have the WebKit rich text editor
  192. // features from Safari 3.0.4, but the version reported is 420.
  193. if ( env.air )
  194. version = parseFloat( agent.match( / adobeair\/(\d+)/ )[1] );
  195. // WebKit 522+ (Safari 3+)
  196. if ( env.webkit )
  197. version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
  198. /**
  199. * Contains the browser version.<br />
  200. * <br />
  201. * For gecko based browsers (like Firefox) it contains the revision
  202. * number with first three parts concatenated with a padding zero
  203. * (e.g. for revision 1.9.0.2 we have 10900).<br />
  204. * <br />
  205. * For webkit based browser (like Safari and Chrome) it contains the
  206. * WebKit build version (e.g. 522).
  207. * @name CKEDITOR.env.version
  208. * @type Boolean
  209. * @example
  210. * if ( CKEDITOR.env.ie && <b>CKEDITOR.env.version</b> <= 6 )
  211. * alert( "Ouch!" );
  212. */
  213. env.version = version;
  214. /**
  215. * Indicates that CKEditor is running on a compatible browser.
  216. * @name CKEDITOR.env.isCompatible
  217. * @type Boolean
  218. * @example
  219. * if ( CKEDITOR.env.isCompatible )
  220. * alert( "Your browser is pretty cool!" );
  221. */
  222. env.isCompatible =
  223. // White list of mobile devices that supports.
  224. env.iOS && version >= 534 ||
  225. !env.mobile && (
  226. ( env.ie && version >= 6 ) ||
  227. ( env.gecko && version >= 10801 ) ||
  228. ( env.opera && version >= 9.5 ) ||
  229. ( env.air && version >= 1 ) ||
  230. ( env.webkit && version >= 522 ) ||
  231. false );
  232. /**
  233. * The CSS class to be appended on the main UI containers, making it
  234. * easy to apply browser specific styles to it.
  235. * @name CKEDITOR.env.cssClass
  236. * @type String
  237. * @example
  238. * myDiv.className = CKEDITOR.env.cssClass;
  239. */
  240. env.cssClass =
  241. 'cke_browser_' + (
  242. env.ie ? 'ie' :
  243. env.gecko ? 'gecko' :
  244. env.opera ? 'opera' :
  245. env.webkit ? 'webkit' :
  246. 'unknown' );
  247. if ( env.quirks )
  248. env.cssClass += ' cke_browser_quirks';
  249. if ( env.ie )
  250. {
  251. env.cssClass += ' cke_browser_ie' + (
  252. env.version < 7 ? '6' :
  253. env.version >= 8 ? document.documentMode:
  254. '7' );
  255. if ( env.quirks )
  256. env.cssClass += ' cke_browser_iequirks';
  257. }
  258. if ( env.gecko && version < 10900 )
  259. env.cssClass += ' cke_browser_gecko18';
  260. if ( env.air )
  261. env.cssClass += ' cke_browser_air';
  262. return env;
  263. })();
  264. }
  265. // PACKAGER_RENAME( CKEDITOR.env )
  266. // PACKAGER_RENAME( CKEDITOR.env.ie )