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