1 /* 2 Copyright (c) 2003-2009, 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 * Environment and browser information. 15 * @namespace 16 * @example 17 */ 18 CKEDITOR.env = (function() 19 { 20 var agent = navigator.userAgent.toLowerCase(); 21 var opera = window.opera; 22 23 var env = 24 /** @lends CKEDITOR.env */ 25 { 26 /** 27 * Indicates that CKEditor is running on Internet Explorer. 28 * @type Boolean 29 * @example 30 * if ( CKEDITOR.env.ie ) 31 * alert( "I'm on IE!" ); 32 */ 33 ie : /*@cc_on!@*/false, 34 35 /** 36 * Indicates that CKEditor is running on Opera. 37 * @type Boolean 38 * @example 39 * if ( CKEDITOR.env.opera ) 40 * alert( "I'm on Opera!" ); 41 */ 42 opera : ( !!opera && opera.version ), 43 44 /** 45 * Indicates that CKEditor is running on a WebKit based browser, like 46 * Safari. 47 * @type Boolean 48 * @example 49 * if ( CKEDITOR.env.webkit ) 50 * alert( "I'm on WebKit!" ); 51 */ 52 webkit : ( agent.indexOf( ' applewebkit/' ) > -1 ), 53 54 /** 55 * Indicates that CKEditor is running on Adobe AIR. 56 * @type Boolean 57 * @example 58 * if ( CKEDITOR.env.air ) 59 * alert( "I'm on AIR!" ); 60 */ 61 air : ( agent.indexOf( ' adobeair/' ) > -1 ), 62 63 /** 64 * Indicates that CKEditor is running on Macintosh. 65 * @type Boolean 66 * @example 67 * if ( CKEDITOR.env.mac ) 68 * alert( "I love apples!" ); 69 */ 70 mac : ( agent.indexOf( 'macintosh' ) > -1 ), 71 72 quirks : ( document.compatMode == 'BackCompat' ), 73 74 isCustomDomain : function() 75 { 76 return this.ie && document.domain != window.location.hostname; 77 } 78 }; 79 80 /** 81 * Indicates that CKEditor is running on a Gecko based browser, like 82 * Firefox. 83 * @name CKEDITOR.env.gecko 84 * @type Boolean 85 * @example 86 * if ( CKEDITOR.env.gecko ) 87 * alert( "I'm riding a gecko!" ); 88 */ 89 env.gecko = ( navigator.product == 'Gecko' && !env.webkit && !env.opera ); 90 91 var version = 0; 92 93 // Internet Explorer 6.0+ 94 if ( env.ie ) 95 { 96 version = parseFloat( agent.match( /msie (\d+)/ )[1] ); 97 98 /** 99 * Indicate IE8 browser. 100 */ 101 env.ie8 = !!document.documentMode; 102 103 /** 104 * Indicte IE8 document mode. 105 */ 106 env.ie8Compat = document.documentMode == 8; 107 108 /** 109 * Indicates that CKEditor is running on an IE7-like environment, which 110 * includes IE7 itself and IE8's IE7 document mode. 111 * @type Boolean 112 */ 113 env.ie7Compat = ( ( version == 7 && !document.documentMode ) 114 || document.documentMode == 7 ); 115 116 /** 117 * Indicates that CKEditor is running on an IE6-like environment, which 118 * includes IE6 itself and IE7 and IE8 quirks mode. 119 * @type Boolean 120 * @example 121 * if ( CKEDITOR.env.ie6Compat ) 122 * alert( "I'm on IE6 or quirks mode!" ); 123 */ 124 env.ie6Compat = ( version < 7 || env.quirks ); 125 126 } 127 128 // Gecko. 129 if ( env.gecko ) 130 { 131 var geckoRelease = agent.match( /rv:([\d\.]+)/ ); 132 if ( geckoRelease ) 133 { 134 geckoRelease = geckoRelease[1].split( '.' ); 135 version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1; 136 } 137 } 138 139 // Opera 9.50+ 140 if ( env.opera ) 141 version = parseFloat( opera.version() ); 142 143 // Adobe AIR 1.0+ 144 // Checked before Safari because AIR have the WebKit rich text editor 145 // features from Safari 3.0.4, but the version reported is 420. 146 if ( env.air ) 147 version = parseFloat( agent.match( / adobeair\/(\d+)/ )[1] ); 148 149 // WebKit 522+ (Safari 3+) 150 if ( env.webkit ) 151 version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] ); 152 153 /** 154 * Contains the browser version. 155 * 156 * For gecko based browsers (like Firefox) it contains the revision 157 * number with first three parts concatenated with a padding zero 158 * (e.g. for revision 1.9.0.2 we have 10900). 159 * 160 * For webkit based browser (like Safari and Chrome) it contains the 161 * WebKit build version (e.g. 522). 162 * @name CKEDITOR.env.version 163 * @type Boolean 164 * @example 165 * if ( CKEDITOR.env.ie && <b>CKEDITOR.env.version</b> <= 6 ) 166 * alert( "Ouch!" ); 167 */ 168 env.version = version; 169 170 /** 171 * Indicates that CKEditor is running on a compatible browser. 172 * @name CKEDITOR.env.isCompatible 173 * @type Boolean 174 * @example 175 * if ( CKEDITOR.env.isCompatible ) 176 * alert( "Your browser is pretty cool!" ); 177 */ 178 env.isCompatible = 179 ( env.ie && version >= 6 ) || 180 ( env.gecko && version >= 10801 ) || 181 ( env.opera && version >= 9.5 ) || 182 ( env.air && version >= 1 ) || 183 ( env.webkit && version >= 522 ) || 184 false; 185 186 // The CSS class to be appended on the main UI containers, making it 187 // easy to apply browser specific styles to it. 188 env.cssClass = 189 'cke_browser_' + ( 190 env.ie ? 'ie' : 191 env.gecko ? 'gecko' : 192 env.opera ? 'opera' : 193 env.air ? 'air' : 194 env.webkit ? 'webkit' : 195 'unknown' ); 196 197 if ( env.quirks ) 198 env.cssClass += ' cke_browser_quirks'; 199 200 if ( env.ie ) 201 { 202 env.cssClass += ' cke_browser_ie' + ( 203 env.version < 7 ? '6' : 204 env.version >= 8 ? '8' : 205 '7' ); 206 207 if ( env.quirks ) 208 env.cssClass += ' cke_browser_iequirks'; 209 } 210 211 if ( env.gecko && version < 10900 ) 212 env.cssClass += ' cke_browser_gecko18'; 213 214 return env; 215 })(); 216 } 217 218 // PACKAGER_RENAME( CKEDITOR.env ) 219 // PACKAGER_RENAME( CKEDITOR.env.ie ) 220