1 /*
  2  * CKEditor - The text editor for Internet - http://ckeditor.com
  3  * Copyright (C) 2003-2008 Frederico Caldeira Knabben
  4  *
  5  * == BEGIN LICENSE ==
  6  *
  7  * Licensed under the terms of any of the following licenses at your
  8  * choice:
  9  *
 10  *  - GNU General Public License Version 2 or later (the "GPL")
 11  *    http://www.gnu.org/licenses/gpl.html
 12  *
 13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 14  *    http://www.gnu.org/licenses/lgpl.html
 15  *
 16  *  - Mozilla Public License Version 1.1 or later (the "MPL")
 17  *    http://www.mozilla.org/MPL/MPL-1.1.html
 18  *
 19  * == END LICENSE ==
 20  */
 21
 22 /**
 23  * @fileOverview Defines the {@link CKEDITOR.env} object, which constains
 24  *		environment and browser information.
 25  */
 26
 27 /**
 28  * Environment and browser information.
 29  * @namespace
 30  * @example
 31  */
 32 CKEDITOR.env = (function()
 33 {
 34 	var agent = navigator.userAgent.toLowerCase();
 35 	var opera = window.opera;
 36
 37 	var env =
 38 	/** @lends CKEDITOR.env */
 39 	{
 40 		/**
 41 		 * Indicates that CKEditor is running on Internet Explorer.
 42 		 * @type Boolean
 43 		 * @example
 44 		 * if ( CKEDITOR.env.ie )
 45 		 *     alert( "I'm on IE!" );
 46 		 */
 47 		ie		: /*@cc_on!@*/false,
 48 		/**
 49 		 * Indicates that CKEditor is running on Opera.
 50 		 * @type Boolean
 51 		 * @example
 52 		 * if ( CKEDITOR.env.opera )
 53 		 *     alert( "I'm on Opera!" );
 54 		 */
 55 		opera	: ( !!opera && opera.version ),
 56 		/**
 57 		 * Indicates that CKEditor is running on a WebKit based browser, like
 58 		 * Safari.
 59 		 * @type Boolean
 60 		 * @example
 61 		 * if ( CKEDITOR.env.webkit )
 62 		 *     alert( "I'm on WebKit!" );
 63 		 */
 64 		webkit	: ( agent.indexOf( ' applewebkit/' ) > -1 ),
 65 		/**
 66 		 * Indicates that CKEditor is running on Adobe AIR.
 67 		 * @type Boolean
 68 		 * @example
 69 		 * if ( CKEDITOR.env.air )
 70 		 *     alert( "I'm on AIR!" );
 71 		 */
 72 		air		: ( agent.indexOf( ' adobeair/' ) > -1 ),
 73 		/**
 74 		 * Indicates that CKEditor is running on Macintosh.
 75 		 * @type Boolean
 76 		 * @example
 77 		 * if ( CKEDITOR.env.mac )
 78 		 *     alert( "I love apples!" );
 79 		 */
 80 		mac	: ( agent.indexOf( 'macintosh' ) > -1 )
 81 	};
 82
 83 	/**
 84 	 * Indicates that CKEditor is running on a Gecko based browser, like
 85 	 * Firefox.
 86 	 * @name CKEDITOR.env.gecko
 87 	 * @type Boolean
 88 	 * @example
 89 	 * if ( CKEDITOR.env.gecko )
 90 	 *     alert( "I'm riding a gecko!" );
 91 	 */
 92 	env.gecko = ( navigator.product == 'Gecko' && !env.webkit && !env.opera );
 93
 94 	/**
 95 	 * Indicates that CKEditor is running on a compatible browser.
 96 	 * @name CKEDITOR.env.isCompatible
 97 	 * @type Boolean
 98 	 * @example
 99 	 * if ( CKEDITOR.env.isCompatible )
100 	 *     alert( "Your browser is pretty cool!" );
101 	 */
102 	env.isCompatible = (function()
103 	{
104 		// Internet Explorer 6.0+
105 		if ( env.ie )
106 			return ( agent.match(/msie (\d+)/)[1] >= 6 );
107
108 		// Gecko.
109 		if ( env.gecko )
110 			return navigator.productSub >= 20030210;
111
112 		// Opera 9.50+
113 		if ( env.opera )
114 			return parseFloat( opera.version() ) >= 9.5;
115
116 		// Adobe AIR 1.0+
117 		// Checked before Safari because AIR have the WebKit rich text editor
118 		// features from Safari 3.0.4, but the version reported is 420.
119 		if ( env.air )
120 			return ( agent.match( / adobeair\/(\d+)/ )[1] >= 1 );
121
122 		// WebKit 522+ (Safari 3+)
123 		if ( env.webkit )
124 			return ( agent.match( / applewebkit\/(\d+)/ )[1] >= 522 );
125
126 		return false;
127 	})();
128
129 	return env;
130 })();
131