]>
git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/core/env.js
cbf089c97d600775bb8dbd074efebfb17e4b649a
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 * @fileOverview Defines the {@link CKEDITOR.env} object which contains
8 * environment and browser information.
11 if ( !CKEDITOR
.env
) {
13 * Environment and browser information.
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
);
26 * Indicates that CKEditor is running in Internet Explorer.
28 * if ( CKEDITOR.env.ie )
29 * alert( 'I\'m running in IE!' );
31 * **Note:** This property is also set to `true` if CKEditor is running
32 * in {@link #edge Microsoft Edge}.
39 * Indicates that CKEditor is running in Microsoft Edge.
41 * if ( CKEDITOR.env.edge )
42 * alert( 'I\'m running in Edge!' );
44 * See also {@link #ie}.
52 * Indicates that CKEditor is running in a WebKit-based browser, like Safari,
53 * or Blink-based browser, like Chrome.
55 * if ( CKEDITOR.env.webkit )
56 * alert( 'I\'m running in a WebKit browser!' );
60 webkit: !ie
&& ( agent
.indexOf( ' applewebkit/' ) > -1 ),
63 * Indicates that CKEditor is running in Adobe AIR.
65 * if ( CKEDITOR.env.air )
66 * alert( 'I\'m on AIR!' );
70 air: ( agent
.indexOf( ' adobeair/' ) > -1 ),
73 * Indicates that CKEditor is running on Macintosh.
75 * if ( CKEDITOR.env.mac )
76 * alert( 'I love apples!'' );
80 mac: ( agent
.indexOf( 'macintosh' ) > -1 ),
83 * Indicates that CKEditor is running in a Quirks Mode environment.
85 * if ( CKEDITOR.env.quirks )
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`.
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`.
95 * Read more: [IEBlog](http://blogs.msdn.com/b/ie/archive/2011/12/14/interoperable-html5-quirks-mode-in-ie10.aspx)
99 quirks: ( document
.compatMode
== 'BackCompat' && ( !document
.documentMode
|| document
.documentMode
< 10 ) ),
102 * Indicates that CKEditor is running in a mobile environemnt.
104 * if ( CKEDITOR.env.mobile )
105 * alert( 'I\'m running with CKEditor today!' );
108 * @property {Boolean}
110 mobile: ( agent
.indexOf( 'mobile' ) > -1 ),
113 * Indicates that CKEditor is running on Apple iPhone/iPad/iPod devices.
115 * if ( CKEDITOR.env.iOS )
116 * alert( 'I like little apples!' );
118 * @property {Boolean}
120 iOS: /(ipad|iphone|ipod)/.test( agent
),
123 * Indicates that the browser has a custom domain enabled. This has
124 * been set with `document.domain`.
126 * if ( CKEDITOR.env.isCustomDomain() )
127 * alert( 'I\'m in a custom domain!' );
129 * @returns {Boolean} `true` if a custom domain is enabled.
132 isCustomDomain: function() {
136 var domain
= document
.domain
,
137 hostname
= window
.location
.hostname
;
139 return domain
!= hostname
&& domain
!= ( '[' + hostname
+ ']' ); // IPv6 IP support (http://dev.ckeditor.com/ticket/5434)
143 * Indicates that the page is running under an encrypted connection.
145 * if ( CKEDITOR.env.secure )
146 * alert( 'I\'m on SSL!' );
148 * @returns {Boolean} `true` if the page has an encrypted connection.
150 secure: location
.protocol
== 'https:'
154 * Indicates that CKEditor is running in a Gecko-based browser, like
157 * if ( CKEDITOR.env.gecko )
158 * alert( 'I\'m riding a gecko!' );
160 * @property {Boolean}
162 env
.gecko
= ( navigator
.product
== 'Gecko' && !env
.webkit
&& !env
.ie
);
165 * Indicates that CKEditor is running in a Blink-based browser like Chrome.
167 * if ( CKEDITOR.env.chrome )
168 * alert( 'I\'m running in Chrome!' );
170 * @property {Boolean} chrome
174 * Indicates that CKEditor is running in Safari (including the mobile version).
176 * if ( CKEDITOR.env.safari )
177 * alert( 'I\'m on Safari!' );
179 * @property {Boolean} safari
182 if ( agent
.indexOf( 'chrome' ) > -1 )
190 // Internet Explorer 6.0+
192 // We use env.version for feature detection, so set it properly.
194 version
= parseFloat( edge
[ 1 ] );
195 } else if ( env
.quirks
|| !document
.documentMode
) {
196 version
= parseFloat( agent
.match( /msie (\d
+)/ )[ 1 ] );
198 version
= document
.documentMode
;
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
;
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.
212 * @property {Boolean} ie6Compat
216 * Indicates that CKEditor is running in an IE7-like environment, which
217 * includes IE7 itself and IE8's IE7 Document Mode.
220 * @property {Boolean} ie7Compat
224 * Indicates that CKEditor is running in Internet Explorer 8 on
228 * @property {Boolean} ie8Compat
232 * Indicates that CKEditor is running in Internet Explorer 9 on
236 * @property {Boolean} ie9Compat
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;
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.
253 version
= parseFloat( agent
.match( / adobeair
\/(\d+)/ )[ 1 ] );
255 // WebKit 522+ (Safari 3+)
257 version
= parseFloat( agent
.match( / applewebkit
\/(\d+)/ )[ 1 ] );
260 * Contains the browser version.
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).
266 * For WebKit-based browsers (like Safari and Chrome) it contains the
267 * WebKit build version (e.g. 522).
269 * For IE browsers, it matches the "Document Mode".
271 * if ( CKEDITOR.env.ie && CKEDITOR.env.version <= 6 )
276 env
.version
= version
;
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.
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.
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.
289 * if ( CKEDITOR.env.isCompatible )
290 * alert( 'Your browser is not known to be incompatible with CKEditor!' );
292 * @property {Boolean}
295 // IE 7+ (IE 7 is not supported, but IE Compat Mode is and it is recognized as IE7).
296 !( env
.ie
&& version
< 7 ) &&
298 !( env
.gecko
&& version
< 40000 ) &&
299 // Chrome 6+, Safari 5.1+, iOS 5+.
300 !( env
.webkit
&& version
< 534 );
303 * Indicates that CKEditor is running in the HiDPI environment.
305 * if ( CKEDITOR.env.hidpi )
306 * alert( 'You are using a screen with high pixel density.' );
308 * @property {Boolean}
310 env
.hidpi
= window
.devicePixelRatio
>= 2;
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.
317 * @property {Boolean}
319 env
.needsBrFiller
= env
.gecko
|| env
.webkit
|| ( env
.ie
&& version
> 10 );
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.
326 * @property {Boolean}
328 env
.needsNbspFiller
= env
.ie
&& version
< 11;
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.
335 * myDiv.className = CKEDITOR.env.cssClass;
339 env
.cssClass
= 'cke_browser_' + ( env
.ie
? 'ie' : env
.gecko
? 'gecko' : env
.webkit
? 'webkit' : 'unknown' );
342 env
.cssClass
+= ' cke_browser_quirks';
345 env
.cssClass
+= ' cke_browser_ie' + ( env
.quirks
? '6 cke_browser_iequirks' : env
.version
);
348 env
.cssClass
+= ' cke_browser_air';
351 env
.cssClass
+= ' cke_browser_ios';
354 env
.cssClass
+= ' cke_hidpi';
360 // PACKAGER_RENAME( CKEDITOR.env )
361 // PACKAGER_RENAME( CKEDITOR.env.ie )