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