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
 75 		/**
 76 		 * Indicates that CKEditor is running on a Gecko based browser, like
 77 		 * Firefox.
 78 		 * @name CKEDITOR.env.gecko
 79 		 * @type Boolean
 80 		 * @example
 81 		 * if ( CKEDITOR.env.gecko )
 82 		 *     alert( "I'm riding a gecko!" );
 83 		 */
 84 		env.gecko = ( navigator.product == 'Gecko' && !env.webkit && !env.opera );
 85
 86 		var version = 0;
 87
 88 		// Internet Explorer 6.0+
 89 		if ( env.ie )
 90 		{
 91 			version = parseFloat( agent.match( /msie (\d+)/ )[1] );
 92
 93 			/**
 94 			 * Indicates that CKEditor is running on an IE6-like environment, which
 95 			 * includes IE6 itself and IE7 and IE8 quirks mode.
 96 			 * @type Boolean
 97 			 * @example
 98 			 * if ( CKEDITOR.env.ie6Compat )
 99 			 *     alert( "I'm on IE6 or quirks mode!" );
100 			 */
101 			env.ie6Compat = ( version < 7 || env.quirks );
102 		}
103
104 		// Gecko.
105 		if ( env.gecko )
106 		{
107 			var geckoRelease = agent.match( /rv:([\d\.]+)/ );
108 			if ( geckoRelease )
109 			{
110 				geckoRelease = geckoRelease[1].split( '.' );
111 				version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 );
112 			}
113 		}
114
115 		// Opera 9.50+
116 		if ( env.opera )
117 			version = parseFloat( opera.version() );
118
119 		// Adobe AIR 1.0+
120 		// Checked before Safari because AIR have the WebKit rich text editor
121 		// features from Safari 3.0.4, but the version reported is 420.
122 		if ( env.air )
123 			version = parseFloat( agent.match( / adobeair\/(\d+)/ )[1] );
124
125 		// WebKit 522+ (Safari 3+)
126 		if ( env.webkit )
127 			version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
128
129 		/**
130 		 * Contains the browser version.
131 		 *
132 		 * For gecko based browsers (like Firefox) it contains the revision
133 		 * number with first three parts concatenated with a padding zero
134 		 * (e.g. for revision 1.9.0.2 we have 10900).
135 		 *
136 		 * For webkit based browser (like Safari and Chrome) it contains the
137 		 * WebKit build version (e.g. 522).
138 		 * @name CKEDITOR.env.version
139 		 * @type Boolean
140 		 * @example
141 		 * if ( CKEDITOR.env.ie && <b>CKEDITOR.env.version</b> <= 6 )
142 		 *     alert( "Ouch!" );
143 		 */
144 		env.version = version;
145
146 		/**
147 		 * Indicates that CKEditor is running on a compatible browser.
148 		 * @name CKEDITOR.env.isCompatible
149 		 * @type Boolean
150 		 * @example
151 		 * if ( CKEDITOR.env.isCompatible )
152 		 *     alert( "Your browser is pretty cool!" );
153 		 */
154 		env.isCompatible =
155 			( env.ie && version >= 6 ) ||
156 			( env.gecko && version >= 10801 ) ||
157 			( env.opera && version >= 9.5 ) ||
158 			( env.air && version >= 1 ) ||
159 			( env.webkit && version >= 522 ) ||
160 			false;
161
162 		return env;
163 	})();
164 }
165
166 // PACKAGER_RENAME( CKEDITOR.env )
167 // PACKAGER_RENAME( CKEDITOR.env.ie )
168