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 Contains the first and essential part of the {@link CKEDITOR}
 24  *		object definition.
 25  */
 26
 27 // #### Compressed Code
 28 // Must be updated on changes in the script, as well as updated in the
 29 // ckeditor_source.js and ckeditor_basic_source.js files.
 30
 31 // if (!window.CKEDITOR){window.CKEDITOR=(function(){return/**@lends CKEDITOR*/{_:{},status:'unloaded',timestamp:'',basePath:(function(){var A='';var B=document.getElementsByTagName('script');for (var i=0;i<B.length;i++){var C=B[i].src.match(/(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?.js(?:\?.*)?$/i);if (C){A=C[1];break;}};if (A.indexOf('://')==-1){if (A.indexOf('/')===0) A=location.href.match(/^.*?:\/\/[^\/]*/)[0]+A;else A=location.href.match(/^[^\?]*\//)[0]+A;};return A;})(),getUrl:function(resource){if (resource.indexOf('://')==-1&&resource.indexOf('/')!==0) resource=this.basePath+resource;if (this.timestamp) resource+=(resource.indexOf('?')>=0?'&':'?')+'t='+this.timestamp;return resource;}};})();};
 32
 33 // #### Raw code
 34 // ATTENTION: read the above "Compressed Code" notes when changing this code.
 35
 36 if ( !window.CKEDITOR )
 37 {
 38 	/**
 39 	 * This is the API entry point. The entire CKEditor code runs under this object.
 40 	 * @name CKEDITOR
 41 	 * @namespace
 42 	 * @example
 43 	 */
 44 	window.CKEDITOR = (function()
 45 	{
 46 		return /** @lends CKEDITOR */ {
 47
 48 			/**
 49 			 * A constant string unique for each release of CKEditor. Its value
 50 			 * is used, by default, to build the URL for all resources loaded
 51 			 * by the editor code, guaranteing clean cache results when
 52 			 * upgrading.
 53 			 * @type String
 54 			 * @example
 55 			 * alert( CKEDITOR.timestamp );  // e.g. '87dm'
 56 			 */
 57 			timestamp : '',				// @Packager.RemoveLine
 58 			/*							// @Packager.RemoveLine
 59 			// The production implementation contains a fixed timestamp, unique
 60 			// for each release, generated by the releaser.
 61 			// (Base 36 value of each component of YYMMDDHH - 4 chars total - e.g. 87bm == 08071122)
 62 			timestamp : '%TIMESTAMP%',
 63 			 */							// @Packager.RemoveLine
 64
 65 			/**
 66 			 * Private object used to hold core stuff. It should not be used out of
 67 			 * the API code as properties defined here may change at any time
 68 			 * without notice.
 69 			 * @private
 70 			 */
 71 			_ : {},
 72
 73 			/**
 74 			 * Indicates the API loading status. The following status are available:
 75 			 *		<ul>
 76 			 *			<li><b>unloaded</b>: the API is not yet loaded.</li>
 77 			 *			<li><b>basic_loaded</b>: the basic API features are available.</li>
 78 			 *			<li><b>basic_ready</b>: the basic API is ready to load the full core code.</li>
 79 			 *			<li><b>loading</b>: the full API is being loaded.</li>
 80 			 *			<li><b>ready</b>: the API can be fully used.</li>
 81 			 *		</ul>
 82 			 * @type String
 83 			 * @example
 84 			 * if ( <b>CKEDITOR.status</b> == 'ready' )
 85 			 * {
 86 			 *     // The API can now be fully used.
 87 			 * }
 88 			 */
 89 			status : 'unloaded',
 90
 91 			/**
 92 			 * Contains the full URL for the CKEditor installation directory.
 93 			 * @type String
 94 			 * @example
 95 			 * alert( <b>CKEDITOR.basePath</b> );  // "http://www.example.com/ckeditor/" (e.g.)
 96 			 */
 97 			basePath : (function()
 98 			{
 99 				// ATTENTION: fixes on this code must be ported to
100 				// var basePath in "core/loader.js".
101
102 				// Find out the editor directory path, based on its <script> tag.
103 				var path = '';
104 				var scripts = document.getElementsByTagName( 'script' );
105
106 				for ( var i = 0 ; i < scripts.length ; i++ )
107 				{
108 					var match = scripts[i].src.match( /(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?.js(?:\?.*)?$/i );
109
110 					if ( match )
111 					{
112 						path = match[1];
113 						break;
114 					}
115 				}
116
117 				// In IE (only) the script.src string is the raw valued entered in the
118 				// HTML. Other browsers return the full resolved URL instead.
119 				if ( path.indexOf('://') == -1 )
120 				{
121 					// Absolute path.
122 					if ( path.indexOf( '/' ) === 0 )
123 						path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path;
124 					// Relative path.
125 					else
126 						path = location.href.match( /^[^\?]*\// )[0] + path;
127 				}
128
129 				return path;
130 			})(),
131
132 			/**
133 			 * Gets the full URL for CKEditor resources. By default, URLs
134 			 * returned by this function contains a querystring parameter ("t")
135 			 * set to the {@link CKEDITOR.timestamp} value.
136 			 * @returns {String} The full URL.
137 			 * @example
138 			 * // e.g. http://www.example.com/ckeditor/skins/default/editor.css?t=87dm
139 			 * alert( CKEDITOR.getUrl( 'skins/default/editor.css' ) );
140 			 * @example
141 			 * // e.g. http://www.example.com/skins/default/editor.css?t=87dm
142 			 * alert( CKEDITOR.getUrl( '/skins/default/editor.css' ) );
143 			 * @example
144 			 * // e.g. http://www.somesite.com/skins/default/editor.css?t=87dm
145 			 * alert( CKEDITOR.getUrl( 'http://www.somesite.com/skins/default/editor.css' ) );
146 			 */
147 			getUrl : function( resource )
148 			{
149 				// If this is not a full or absolute path.
150 				if ( resource.indexOf('://') == -1 && resource.indexOf( '/' ) !== 0 )
151 					resource = this.basePath + resource;
152
153 				if ( this.timestamp )
154 					resource += ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 't=' + this.timestamp;
155
156 				return resource;
157 			}
158 		};
159 	})();
160 }
161