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