1 /* 2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 /** 7 * @fileOverview Contains the first and essential part of the {@link CKEDITOR} 8 * object definition. 9 */ 10 11 // #### Compressed Code 12 // Must be updated on changes in the script as well as updated in the 13 // ckeditor_source.js and ckeditor_basic_source.js files. 14 15 // if(!window.CKEDITOR)window.CKEDITOR=(function(){var a={timestamp:'',version:'%VERSION%',revision:'%REV%',rnd:Math.floor(Math.random()*900)+100,_:{},status:'unloaded',basePath:(function(){var d=window.CKEDITOR_BASEPATH||'';if(!d){var e=document.getElementsByTagName('script');for(var f=0;f<e.length;f++){var g=e[f].src.match(/(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?.js(?:\?.*)?$/i);if(g){d=g[1];break;}}}if(d.indexOf(':/')==-1)if(d.indexOf('/')===0)d=location.href.match(/^.*?:\/\/[^\/]*/)[0]+d;else d=location.href.match(/^[^\?]*\/(?:)/)[0]+d;if(!d)throw 'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.';return d;})(),getUrl:function(d){if(d.indexOf(':/')==-1&&d.indexOf('/')!==0)d=this.basePath+d;if(this.timestamp&&d.charAt(d.length-1)!='/'&&!/[&?]t=/.test(d))d+=(d.indexOf('?')>=0?'&':'?')+'t='+this.timestamp;return d;}},b=window.CKEDITOR_GETURL;if(b){var c=a.getUrl;a.getUrl=function(d){return b.call(a,d)||c.call(a,d);};}return a;})(); 16 17 // #### Raw code 18 // ATTENTION: read the above "Compressed Code" notes when changing this code. 19 20 /* @Packager.RemoveLine 21 // Avoid having the editor code initialized twice. (#7588) 22 // Use CKEDITOR.dom to check whether the full ckeditor.js code has been loaded 23 // or just ckeditor_basic.js. 24 // Remove these lines when compressing manually. 25 if ( window.CKEDITOR && window.CKEDITOR.dom ) 26 return; 27 @Packager.RemoveLine */ 28 29 if ( !window.CKEDITOR ) 30 { 31 /** 32 * @name CKEDITOR 33 * @namespace This is the API entry point. The entire CKEditor code runs under this object. 34 * @example 35 */ 36 window.CKEDITOR = (function() 37 { 38 var CKEDITOR = 39 /** @lends CKEDITOR */ 40 { 41 42 /** 43 * A constant string unique for each release of CKEditor. Its value 44 * is used, by default, to build the URL for all resources loaded 45 * by the editor code, guaranteeing clean cache results when 46 * upgrading. 47 * @type String 48 * @example 49 * alert( CKEDITOR.timestamp ); // e.g. '87dm' 50 */ 51 timestamp : '', // %REMOVE_LINE% 52 /* // %REMOVE_LINE% 53 // The production implementation contains a fixed timestamp, unique 54 // for each release and generated by the releaser. 55 // (Base 36 value of each component of YYMMDDHH - 4 chars total - e.g. 87bm == 08071122) 56 timestamp : '%TIMESTAMP%', 57 */ // %REMOVE_LINE% 58 59 /** 60 * Contains the CKEditor version number. 61 * @type String 62 * @example 63 * alert( CKEDITOR.version ); // e.g. 'CKEditor 3.4.1' 64 */ 65 version : '%VERSION%', 66 67 /** 68 * Contains the CKEditor revision number. 69 * The revision number is incremented automatically, following each 70 * modification to the CKEditor source code. 71 * @type String 72 * @example 73 * alert( CKEDITOR.revision ); // e.g. '3975' 74 */ 75 revision : '%REV%', 76 77 /** 78 * A 3-digit random integer, valid for the entire life of the CKEDITOR object. 79 * @type Number 80 * @example 81 * alert( CKEDITOR.rnd ); // e.g. '319' 82 */ 83 rnd : Math.floor( Math.random() * ( 999/*Max*/ - 100/*Min*/ + 1 ) ) + 100/*Min*/, 84 85 /** 86 * Private object used to hold core stuff. It should not be used outside of 87 * the API code as properties defined here may change at any time 88 * without notice. 89 * @private 90 */ 91 _ : {}, 92 93 /** 94 * Indicates the API loading status. The following statuses are available: 95 * <ul> 96 * <li><b>unloaded</b>: the API is not yet loaded.</li> 97 * <li><b>basic_loaded</b>: the basic API features are available.</li> 98 * <li><b>basic_ready</b>: the basic API is ready to load the full core code.</li> 99 * <li><b>loading</b>: the full API is being loaded.</li> 100 * <li><b>loaded</b>: the API can be fully used.</li> 101 * </ul> 102 * @type String 103 * @example 104 * if ( <b>CKEDITOR.status</b> == 'loaded' ) 105 * { 106 * // The API can now be fully used. 107 * } 108 */ 109 status : 'unloaded', 110 111 /** 112 * Contains the full URL for the CKEditor installation directory. 113 * It is possible to manually provide the base path by setting a 114 * global variable named CKEDITOR_BASEPATH. This global variable 115 * must be set <strong>before</strong> the editor script loading. 116 * @type String 117 * @example 118 * alert( <b>CKEDITOR.basePath</b> ); // "http://www.example.com/ckeditor/" (e.g.) 119 */ 120 basePath : (function() 121 { 122 // ATTENTION: fixes to this code must be ported to 123 // var basePath in "core/loader.js". 124 125 // Find out the editor directory path, based on its <script> tag. 126 var path = window.CKEDITOR_BASEPATH || ''; 127 128 if ( !path ) 129 { 130 var scripts = document.getElementsByTagName( 'script' ); 131 132 for ( var i = 0 ; i < scripts.length ; i++ ) 133 { 134 var match = scripts[i].src.match( /(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?.js(?:\?.*)?$/i ); 135 136 if ( match ) 137 { 138 path = match[1]; 139 break; 140 } 141 } 142 } 143 144 // In IE (only) the script.src string is the raw value entered in the 145 // HTML source. Other browsers return the full resolved URL instead. 146 if ( path.indexOf(':/') == -1 ) 147 { 148 // Absolute path. 149 if ( path.indexOf( '/' ) === 0 ) 150 path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path; 151 // Relative path. 152 else 153 path = location.href.match( /^[^\?]*\/(?:)/ )[0] + path; 154 } 155 156 if ( !path ) 157 throw 'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.'; 158 159 return path; 160 })(), 161 162 /** 163 * Gets the full URL for CKEditor resources. By default, URLs 164 * returned by this function contain a querystring parameter ("t") 165 * set to the {@link CKEDITOR.timestamp} value.<br /> 166 * <br /> 167 * It is possible to provide a custom implementation of this 168 * function by setting a global variable named CKEDITOR_GETURL. 169 * This global variable must be set <strong>before</strong> the editor script 170 * loading. If the custom implementation returns nothing (==null), the 171 * default implementation is used. 172 * @param {String} resource The resource whose full URL we want to get. 173 * It may be a full, absolute, or relative URL. 174 * @returns {String} The full URL. 175 * @example 176 * // e.g. http://www.example.com/ckeditor/skins/default/editor.css?t=87dm 177 * alert( CKEDITOR.getUrl( 'skins/default/editor.css' ) ); 178 * @example 179 * // e.g. http://www.example.com/skins/default/editor.css?t=87dm 180 * alert( CKEDITOR.getUrl( '/skins/default/editor.css' ) ); 181 * @example 182 * // e.g. http://www.somesite.com/skins/default/editor.css?t=87dm 183 * alert( CKEDITOR.getUrl( 'http://www.somesite.com/skins/default/editor.css' ) ); 184 */ 185 getUrl : function( resource ) 186 { 187 // If this is not a full or absolute path. 188 if ( resource.indexOf(':/') == -1 && resource.indexOf( '/' ) !== 0 ) 189 resource = this.basePath + resource; 190 191 // Add the timestamp, except for directories. 192 if ( this.timestamp && resource.charAt( resource.length - 1 ) != '/' && !(/[&?]t=/).test( resource ) ) 193 resource += ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 't=' + this.timestamp; 194 195 return resource; 196 } 197 }; 198 199 // Make it possible to override the getUrl function with a custom 200 // implementation pointing to a global named CKEDITOR_GETURL. 201 var newGetUrl = window.CKEDITOR_GETURL; 202 if ( newGetUrl ) 203 { 204 var originalGetUrl = CKEDITOR.getUrl; 205 CKEDITOR.getUrl = function ( resource ) 206 { 207 return newGetUrl.call( CKEDITOR, resource ) || 208 originalGetUrl.call( CKEDITOR, resource ); 209 }; 210 } 211 212 return CKEDITOR; 213 })(); 214 } 215 216 /** 217 * Function called upon loading a custom configuration file that can 218 * modify the editor instance configuration ({@link CKEDITOR.editor#config }). 219 * It is usually defined inside the custom configuration files that can 220 * include developer defined settings. 221 * @name CKEDITOR.editorConfig 222 * @function 223 * @param {CKEDITOR.config} config A configuration object containing the 224 * settings defined for a {@link CKEDITOR.editor} instance up to this 225 * function call. Note that not all settings may still be available. See 226 * <a href="http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Setting_Configurations#Configuration_Loading_Order">Configuration Loading Order</a> 227 * for details. 228 * @example 229 * // This is supposed to be placed in the config.js file. 230 * CKEDITOR.editorConfig = function( config ) 231 * { 232 * // Define changes to default configuration here. For example: 233 * config.language = 'fr'; 234 * config.uiColor = '#AADC6E'; 235 * }; 236 */ 237 238 // PACKAGER_RENAME( CKEDITOR ) 239