JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / core / ckeditor_base.js
1 /*\r
2 Copyright (c) 2003-2012, 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.6.3',revision:'7474',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;})();\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 : 'C3HA5RM',\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.6.3',\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 : '7474',\r
73 \r
74                         /**\r
75                          * A 3-digit random integer, valid for the entire life of the CKEDITOR object.\r
76                          * @type Number\r
77                          * @example\r
78                          * alert( CKEDITOR.rnd );  // e.g. '319'\r
79                          */\r
80                         rnd : Math.floor( Math.random() * ( 999/*Max*/ - 100/*Min*/ + 1 ) ) + 100/*Min*/,\r
81 \r
82                         /**\r
83                          * Private object used to hold core stuff. It should not be used outside of\r
84                          * the API code as properties defined here may change at any time\r
85                          * without notice.\r
86                          * @private\r
87                          */\r
88                         _ : {},\r
89 \r
90                         /**\r
91                          * Indicates the API loading status. The following statuses are available:\r
92                          *              <ul>\r
93                          *                      <li><b>unloaded</b>: the API is not yet loaded.</li>\r
94                          *                      <li><b>basic_loaded</b>: the basic API features are available.</li>\r
95                          *                      <li><b>basic_ready</b>: the basic API is ready to load the full core code.</li>\r
96                          *                      <li><b>loading</b>: the full API is being loaded.</li>\r
97                          *                      <li><b>loaded</b>: the API can be fully used.</li>\r
98                          *              </ul>\r
99                          * @type String\r
100                          * @example\r
101                          * if ( <b>CKEDITOR.status</b> == 'loaded' )\r
102                          * {\r
103                          *     // The API can now be fully used.\r
104                          * }\r
105                          */\r
106                         status : 'unloaded',\r
107 \r
108                         /**\r
109                          * Contains the full URL for the CKEditor installation directory.\r
110                          * It is possible to manually provide the base path by setting a\r
111                          * global variable named CKEDITOR_BASEPATH. This global variable\r
112                          * must be set <strong>before</strong> the editor script loading.\r
113                          * @type String\r
114                          * @example\r
115                          * alert( <b>CKEDITOR.basePath</b> );  // "http://www.example.com/ckeditor/" (e.g.)\r
116                          */\r
117                         basePath : (function()\r
118                         {\r
119                                 // ATTENTION: fixes to this code must be ported to\r
120                                 // var basePath in "core/loader.js".\r
121 \r
122                                 // Find out the editor directory path, based on its <script> tag.\r
123                                 var path = window.CKEDITOR_BASEPATH || '';\r
124 \r
125                                 if ( !path )\r
126                                 {\r
127                                         var scripts = document.getElementsByTagName( 'script' );\r
128 \r
129                                         for ( var i = 0 ; i < scripts.length ; i++ )\r
130                                         {\r
131                                                 var match = scripts[i].src.match( /(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?.js(?:\?.*)?$/i );\r
132 \r
133                                                 if ( match )\r
134                                                 {\r
135                                                         path = match[1];\r
136                                                         break;\r
137                                                 }\r
138                                         }\r
139                                 }\r
140 \r
141                                 // In IE (only) the script.src string is the raw value entered in the\r
142                                 // HTML source. Other browsers return the full resolved URL instead.\r
143                                 if ( path.indexOf(':/') == -1 )\r
144                                 {\r
145                                         // Absolute path.\r
146                                         if ( path.indexOf( '/' ) === 0 )\r
147                                                 path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path;\r
148                                         // Relative path.\r
149                                         else\r
150                                                 path = location.href.match( /^[^\?]*\/(?:)/ )[0] + path;\r
151                                 }\r
152 \r
153                                 if ( !path )\r
154                                                 throw 'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.';\r
155 \r
156                                 return path;\r
157                         })(),\r
158 \r
159                         /**\r
160                          * Gets the full URL for CKEditor resources. By default, URLs\r
161                          * returned by this function contain a querystring parameter ("t")\r
162                          * set to the {@link CKEDITOR.timestamp} value.<br />\r
163                          * <br />\r
164                          * It is possible to provide a custom implementation of this\r
165                          * function by setting a global variable named CKEDITOR_GETURL.\r
166                          * This global variable must be set <strong>before</strong> the editor script\r
167                          * loading. If the custom implementation returns nothing (==null), the\r
168                          * default implementation is used.\r
169                          * @param {String} resource The resource whose full URL we want to get.\r
170                          *              It may be a full, absolute, or relative URL.\r
171                          * @returns {String} The full URL.\r
172                          * @example\r
173                          * // e.g. http://www.example.com/ckeditor/skins/default/editor.css?t=87dm\r
174                          * alert( CKEDITOR.getUrl( 'skins/default/editor.css' ) );\r
175                          * @example\r
176                          * // e.g. http://www.example.com/skins/default/editor.css?t=87dm\r
177                          * alert( CKEDITOR.getUrl( '/skins/default/editor.css' ) );\r
178                          * @example\r
179                          * // e.g. http://www.somesite.com/skins/default/editor.css?t=87dm\r
180                          * alert( CKEDITOR.getUrl( 'http://www.somesite.com/skins/default/editor.css' ) );\r
181                          */\r
182                         getUrl : function( resource )\r
183                         {\r
184                                 // If this is not a full or absolute path.\r
185                                 if ( resource.indexOf(':/') == -1 && resource.indexOf( '/' ) !== 0 )\r
186                                         resource = this.basePath + resource;\r
187 \r
188                                 // Add the timestamp, except for directories.\r
189                                 if ( this.timestamp && resource.charAt( resource.length - 1 ) != '/' && !(/[&?]t=/).test( resource ) )\r
190                                         resource += ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 't=' + this.timestamp;\r
191 \r
192                                 return resource;\r
193                         }\r
194                 };\r
195 \r
196                 // Make it possible to override the getUrl function with a custom\r
197                 // implementation pointing to a global named CKEDITOR_GETURL.\r
198                 var newGetUrl = window.CKEDITOR_GETURL;\r
199                 if ( newGetUrl )\r
200                 {\r
201                         var originalGetUrl = CKEDITOR.getUrl;\r
202                         CKEDITOR.getUrl = function ( resource )\r
203                         {\r
204                                 return newGetUrl.call( CKEDITOR, resource ) ||\r
205                                         originalGetUrl.call( CKEDITOR, resource );\r
206                         };\r
207                 }\r
208 \r
209                 return CKEDITOR;\r
210         })();\r
211 }\r
212 \r
213 /**\r
214  * Function called upon loading a custom configuration file that can\r
215  * modify the editor instance configuration ({@link CKEDITOR.editor#config }).\r
216  * It is usually defined inside the custom configuration files that can\r
217  * include developer defined settings.\r
218  * @name CKEDITOR.editorConfig\r
219  * @function\r
220  * @param {CKEDITOR.config} config A configuration object containing the\r
221  *              settings defined for a {@link CKEDITOR.editor} instance up to this\r
222  *              function call. Note that not all settings may still be available. See\r
223  *              <a href="http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Setting_Configurations#Configuration_Loading_Order">Configuration Loading Order</a>\r
224  *              for details.\r
225  * @example\r
226  * // This is supposed to be placed in the config.js file.\r
227  * CKEDITOR.editorConfig = function( config )\r
228  * {\r
229  *     // Define changes to default configuration here. For example:\r
230  *     config.language = 'fr';\r
231  *     config.uiColor = '#AADC6E';\r
232  * };\r
233  */\r
234 \r
235 // PACKAGER_RENAME( CKEDITOR )\r