2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview Defines the {@link CKEDITOR.env} object, which constains
8 * environment and browser information.
14 * @namespace Environment and browser information.
16 CKEDITOR.env = (function()
18 var agent = navigator.userAgent.toLowerCase();
19 var opera = window.opera;
22 /** @lends CKEDITOR.env */
25 * Indicates that CKEditor is running on Internet Explorer.
28 * if ( CKEDITOR.env.ie )
29 * alert( "I'm on IE!" );
31 ie : /*@cc_on!@*/false,
34 * Indicates that CKEditor is running on Opera.
37 * if ( CKEDITOR.env.opera )
38 * alert( "I'm on Opera!" );
40 opera : ( !!opera && opera.version ),
43 * Indicates that CKEditor is running on a WebKit based browser, like
47 * if ( CKEDITOR.env.webkit )
48 * alert( "I'm on WebKit!" );
50 webkit : ( agent.indexOf( ' applewebkit/' ) > -1 ),
53 * Indicates that CKEditor is running on Adobe AIR.
56 * if ( CKEDITOR.env.air )
57 * alert( "I'm on AIR!" );
59 air : ( agent.indexOf( ' adobeair/' ) > -1 ),
62 * Indicates that CKEditor is running on Macintosh.
65 * if ( CKEDITOR.env.mac )
66 * alert( "I love apples!" );
68 mac : ( agent.indexOf( 'macintosh' ) > -1 ),
71 * Indicates that CKEditor is running on a quirks mode environemnt.
74 * if ( CKEDITOR.env.quirks )
77 quirks : ( document.compatMode == 'BackCompat' ),
80 * Indicates that CKEditor is running on a mobile like environemnt.
83 * if ( CKEDITOR.env.mobile )
84 * alert( "I'm running with CKEditor today!" );
86 mobile : ( agent.indexOf( 'mobile' ) > -1 ),
89 * Indicates that the browser has a custom domain enabled. This has
90 * been set with "document.domain".
91 * @returns {Boolean} "true" if a custom domain is enabled.
93 * if ( CKEDITOR.env.isCustomDomain() )
94 * alert( "I'm in a custom domain!" );
96 isCustomDomain : function()
101 var domain = document.domain,
102 hostname = window.location.hostname;
104 return domain != hostname &&
105 domain != ( '[' + hostname + ']' ); // IPv6 IP support (#5434)
110 * Indicates that CKEditor is running on a Gecko based browser, like
112 * @name CKEDITOR.env.gecko
115 * if ( CKEDITOR.env.gecko )
116 * alert( "I'm riding a gecko!" );
118 env.gecko = ( navigator.product == 'Gecko' && !env.webkit && !env.opera );
122 // Internet Explorer 6.0+
125 version = parseFloat( agent.match( /msie (\d+)/ )[1] );
128 * Indicates that CKEditor is running on Internet Explorer 8.
129 * @name CKEDITOR.env.ie8
132 * if ( CKEDITOR.env.ie8 )
133 * alert( "I'm on IE8!" );
135 env.ie8 = !!document.documentMode;
138 * Indicates that CKEditor is running on Internet Explorer 8 on
140 * @name CKEDITOR.env.ie8Compat
143 * if ( CKEDITOR.env.ie8Compat )
144 * alert( "Now I'm on IE8, for real!" );
146 env.ie8Compat = document.documentMode == 8;
149 * Indicates that CKEditor is running on an IE7-like environment, which
150 * includes IE7 itself and IE8's IE7 document mode.
151 * @name CKEDITOR.env.ie7Compat
154 * if ( CKEDITOR.env.ie8Compat )
155 * alert( "I'm on IE7 or on an IE7 like IE8!" );
157 env.ie7Compat = ( ( version == 7 && !document.documentMode )
158 || document.documentMode == 7 );
161 * Indicates that CKEditor is running on an IE6-like environment, which
162 * includes IE6 itself and IE7 and IE8 quirks mode.
163 * @name CKEDITOR.env.ie6Compat
166 * if ( CKEDITOR.env.ie6Compat )
167 * alert( "I'm on IE6 or quirks mode!" );
169 env.ie6Compat = ( version < 7 || env.quirks );
175 var geckoRelease = agent.match( /rv:([\d\.]+)/ );
178 geckoRelease = geckoRelease[1].split( '.' );
179 version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1;
185 version = parseFloat( opera.version() );
188 // Checked before Safari because AIR have the WebKit rich text editor
189 // features from Safari 3.0.4, but the version reported is 420.
191 version = parseFloat( agent.match( / adobeair\/(\d+)/ )[1] );
193 // WebKit 522+ (Safari 3+)
195 version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
198 * Contains the browser version.<br />
200 * For gecko based browsers (like Firefox) it contains the revision
201 * number with first three parts concatenated with a padding zero
202 * (e.g. for revision 1.9.0.2 we have 10900).<br />
204 * For webkit based browser (like Safari and Chrome) it contains the
205 * WebKit build version (e.g. 522).
206 * @name CKEDITOR.env.version
209 * if ( CKEDITOR.env.ie && <b>CKEDITOR.env.version</b> <= 6 )
212 env.version = version;
215 * Indicates that CKEditor is running on a compatible browser.
216 * @name CKEDITOR.env.isCompatible
219 * if ( CKEDITOR.env.isCompatible )
220 * alert( "Your browser is pretty cool!" );
224 ( env.ie && version >= 6 ) ||
225 ( env.gecko && version >= 10801 ) ||
226 ( env.opera && version >= 9.5 ) ||
227 ( env.air && version >= 1 ) ||
228 ( env.webkit && version >= 522 ) ||
232 * The CSS class to be appended on the main UI containers, making it
233 * easy to apply browser specific styles to it.
234 * @name CKEDITOR.env.cssClass
237 * myDiv.className = CKEDITOR.env.cssClass;
242 env.gecko ? 'gecko' :
243 env.opera ? 'opera' :
244 env.webkit ? 'webkit' :
248 env.cssClass += ' cke_browser_quirks';
252 env.cssClass += ' cke_browser_ie' + (
253 env.version < 7 ? '6' :
254 env.version >= 8 ? document.documentMode:
258 env.cssClass += ' cke_browser_iequirks';
261 if ( env.gecko && version < 10900 )
262 env.cssClass += ' cke_browser_gecko18';
265 env.cssClass += ' cke_browser_air';
271 // PACKAGER_RENAME( CKEDITOR.env )
272 // PACKAGER_RENAME( CKEDITOR.env.ie )