initial commit
[namibia] / public / scripts / ckeditor / _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 CKEditor is running on Apple iPhone/iPad/iPod devices.
90                          * @type Boolean
91                          * @example
92                          * if ( CKEDITOR.env.iOS )
93                          *     alert( "I like little apples!" );
94                          */
95                         iOS : /(ipad|iphone|ipod)/.test(agent),
96
97                         /**
98                          * Indicates that the browser has a custom domain enabled. This has
99                          * been set with "document.domain".
100                          * @returns {Boolean} "true" if a custom domain is enabled.
101                          * @example
102                          * if ( CKEDITOR.env.isCustomDomain() )
103                          *     alert( "I'm in a custom domain!" );
104                          */
105                         isCustomDomain : function()
106                         {
107                                 if ( !this.ie )
108                                         return false;
109
110                                 var domain = document.domain,
111                                         hostname = window.location.hostname;
112
113                                 return domain != hostname &&
114                                         domain != ( '[' + hostname + ']' );     // IPv6 IP support (#5434)
115                         },
116
117                         /**
118                          * Indicates that page is running under an encrypted connection.
119                          * @returns {Boolean} "true" if the page has an encrypted connection.
120                          * @example
121                          * if ( CKEDITOR.env.secure )
122                          *     alert( "I'm in SSL!" );
123                          */
124                         secure : location.protocol == 'https:'
125                 };
126
127                 /**
128                  * Indicates that CKEditor is running on a Gecko based browser, like
129                  * Firefox.
130                  * @name CKEDITOR.env.gecko
131                  * @type Boolean
132                  * @example
133                  * if ( CKEDITOR.env.gecko )
134                  *     alert( "I'm riding a gecko!" );
135                  */
136                 env.gecko = ( navigator.product == 'Gecko' && !env.webkit && !env.opera );
137
138                 var version = 0;
139
140                 // Internet Explorer 6.0+
141                 if ( env.ie )
142                 {
143                         version = parseFloat( agent.match( /msie (\d+)/ )[1] );
144
145                         /**
146                          * Indicates that CKEditor is running on Internet Explorer 8.
147                          * @name CKEDITOR.env.ie8
148                          * @type Boolean
149                          * @example
150                          * if ( CKEDITOR.env.ie8 )
151                          *     alert( "I'm on IE8!" );
152                          */
153                         env.ie8 = !!document.documentMode;
154
155                         /**
156                          * Indicates that CKEditor is running on Internet Explorer 8 on
157                          * standards mode.
158                          * @name CKEDITOR.env.ie8Compat
159                          * @type Boolean
160                          * @example
161                          * if ( CKEDITOR.env.ie8Compat )
162                          *     alert( "Now I'm on IE8, for real!" );
163                          */
164                         env.ie8Compat = document.documentMode == 8;
165
166                         /**
167                          * Indicates that CKEditor is running on Internet Explorer 9's standards mode.
168                          * @name CKEDITOR.env.ie9Compat
169                          * @type Boolean
170                          * @example
171                          * if ( CKEDITOR.env.ie9Compat )
172                          *     alert( "IE9, the beauty of the web!" );
173                          */
174                         env.ie9Compat = document.documentMode == 9;
175
176                         /**
177                          * Indicates that CKEditor is running on an IE7-like environment, which
178                          * includes IE7 itself and IE8's IE7 document mode.
179                          * @name CKEDITOR.env.ie7Compat
180                          * @type Boolean
181                          * @example
182                          * if ( CKEDITOR.env.ie8Compat )
183                          *     alert( "I'm on IE7 or on an IE7 like IE8!" );
184                          */
185                         env.ie7Compat = ( ( version == 7 && !document.documentMode )
186                                         || document.documentMode == 7 );
187
188                         /**
189                          * Indicates that CKEditor is running on an IE6-like environment, which
190                          * includes IE6 itself and IE7 and IE8 quirks mode.
191                          * @name CKEDITOR.env.ie6Compat
192                          * @type Boolean
193                          * @example
194                          * if ( CKEDITOR.env.ie6Compat )
195                          *     alert( "I'm on IE6 or quirks mode!" );
196                          */
197                         env.ie6Compat = ( version < 7 || env.quirks );
198                 }
199
200                 // Gecko.
201                 if ( env.gecko )
202                 {
203                         var geckoRelease = agent.match( /rv:([\d\.]+)/ );
204                         if ( geckoRelease )
205                         {
206                                 geckoRelease = geckoRelease[1].split( '.' );
207                                 version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1;
208                         }
209                 }
210
211                 // Opera 9.50+
212                 if ( env.opera )
213                         version = parseFloat( opera.version() );
214
215                 // Adobe AIR 1.0+
216                 // Checked before Safari because AIR have the WebKit rich text editor
217                 // features from Safari 3.0.4, but the version reported is 420.
218                 if ( env.air )
219                         version = parseFloat( agent.match( / adobeair\/(\d+)/ )[1] );
220
221                 // WebKit 522+ (Safari 3+)
222                 if ( env.webkit )
223                         version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
224
225                 /**
226                  * Contains the browser version.<br />
227                  * <br />
228                  * For gecko based browsers (like Firefox) it contains the revision
229                  * number with first three parts concatenated with a padding zero
230                  * (e.g. for revision 1.9.0.2 we have 10900).<br />
231                  * <br />
232                  * For webkit based browser (like Safari and Chrome) it contains the
233                  * WebKit build version (e.g. 522).
234                  * @name CKEDITOR.env.version
235                  * @type Boolean
236                  * @example
237                  * if ( CKEDITOR.env.ie && <b>CKEDITOR.env.version</b> <= 6 )
238                  *     alert( "Ouch!" );
239                  */
240                 env.version = version;
241
242                 /**
243                  * Indicates that CKEditor is running on a compatible browser.
244                  * @name CKEDITOR.env.isCompatible
245                  * @type Boolean
246                  * @example
247                  * if ( CKEDITOR.env.isCompatible )
248                  *     alert( "Your browser is pretty cool!" );
249                  */
250                 env.isCompatible =
251
252                         // White list of mobile devices that supports.
253                         env.iOS && version >= 534 ||
254
255                         !env.mobile && (
256
257                         ( env.ie && version >= 6 ) ||
258                         ( env.gecko && version >= 10801 ) ||
259                         ( env.opera && version >= 9.5 ) ||
260                         ( env.air && version >= 1 ) ||
261                         ( env.webkit && version >= 522 ) ||
262                         false );
263
264                 /**
265                  * The CSS class to be appended on the main UI containers, making it
266                  * easy to apply browser specific styles to it.
267                  * @name CKEDITOR.env.cssClass
268                  * @type String
269                  * @example
270                  * myDiv.className = CKEDITOR.env.cssClass;
271                  */
272                 env.cssClass =
273                         'cke_browser_' + (
274                                 env.ie ? 'ie' :
275                                 env.gecko ? 'gecko' :
276                                 env.opera ? 'opera' :
277                                 env.webkit ? 'webkit' :
278                                 'unknown' );
279
280                 if ( env.quirks )
281                         env.cssClass += ' cke_browser_quirks';
282
283                 if ( env.ie )
284                 {
285                         env.cssClass += ' cke_browser_ie' + (
286                                 env.version < 7 ? '6' :
287                                 env.version >= 8 ? document.documentMode:
288                                 '7' );
289
290                         if ( env.quirks )
291                                 env.cssClass += ' cke_browser_iequirks';
292                 }
293
294                 if ( env.gecko && version < 10900 )
295                         env.cssClass += ' cke_browser_gecko18';
296
297                 if ( env.air )
298                         env.cssClass += ' cke_browser_air';
299
300                 return env;
301         })();
302 }
303
304 // PACKAGER_RENAME( CKEDITOR.env )
305 // PACKAGER_RENAME( CKEDITOR.env.ie )