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