JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
48b8072258c738fe99693b82d01526e95e7d7a81
[ckeditor.git] / _source / core / ckeditor_base.js
1 /*\r
2 Copyright (c) 2003-2010, 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.4 Beta',rev:'5808',_:{},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 if ( !window.CKEDITOR )\r
21 {\r
22         /**\r
23          * This is the API entry point. The entire CKEditor code runs under this object.\r
24          * @name CKEDITOR\r
25          * @namespace\r
26          * @example\r
27          */\r
28         window.CKEDITOR = (function()\r
29         {\r
30                 var CKEDITOR =\r
31                 /** @lends CKEDITOR */\r
32                 {\r
33 \r
34                         /**\r
35                          * A constant string unique for each release of CKEditor. Its value\r
36                          * is used, by default, to build the URL for all resources loaded\r
37                          * by the editor code, guaranteing clean cache results when\r
38                          * upgrading.\r
39                          * @type String\r
40                          * @example\r
41                          * alert( CKEDITOR.timestamp );  // e.g. '87dm'\r
42                          */\r
43                         // The production implementation contains a fixed timestamp, unique\r
44                         // for each release, generated by the releaser.\r
45                         // (Base 36 value of each component of YYMMDDHH - 4 chars total - e.g. 87bm == 08071122)\r
46                         timestamp : 'A73H4HC',\r
47 \r
48                         /**\r
49                          * Contains the CKEditor version number.\r
50                          * @type String\r
51                          * @example\r
52                          * alert( CKEDITOR.version );  // e.g. 'CKEditor 3.0 Beta'\r
53                          */\r
54                         version : '3.4 Beta',\r
55 \r
56                         /**\r
57                          * Contains the CKEditor revision number.\r
58                          * Revision number is incremented automatically after each modification of CKEditor source code.\r
59                          * @type String\r
60                          * @example\r
61                          * alert( CKEDITOR.revision );  // e.g. '3975'\r
62                          */\r
63                         revision : '5808',\r
64 \r
65                         /**\r
66                          * Private object used to hold core stuff. It should not be used out of\r
67                          * the API code as properties defined here may change at any time\r
68                          * without notice.\r
69                          * @private\r
70                          */\r
71                         _ : {},\r
72 \r
73                         /**\r
74                          * Indicates the API loading status. The following status are available:\r
75                          *              <ul>\r
76                          *                      <li><b>unloaded</b>: the API is not yet loaded.</li>\r
77                          *                      <li><b>basic_loaded</b>: the basic API features are available.</li>\r
78                          *                      <li><b>basic_ready</b>: the basic API is ready to load the full core code.</li>\r
79                          *                      <li><b>loading</b>: the full API is being loaded.</li>\r
80                          *                      <li><b>ready</b>: the API can be fully used.</li>\r
81                          *              </ul>\r
82                          * @type String\r
83                          * @example\r
84                          * if ( <b>CKEDITOR.status</b> == 'ready' )\r
85                          * {\r
86                          *     // The API can now be fully used.\r
87                          * }\r
88                          */\r
89                         status : 'unloaded',\r
90 \r
91                         /**\r
92                          * Contains the full URL for the CKEditor installation directory.\r
93                          * It's possible to manually provide the base path by setting a\r
94                          * global variable named CKEDITOR_BASEPATH. This global variable\r
95                          * must be set "before" the editor script loading.\r
96                          * @type String\r
97                          * @example\r
98                          * alert( <b>CKEDITOR.basePath</b> );  // "http://www.example.com/ckeditor/" (e.g.)\r
99                          */\r
100                         basePath : (function()\r
101                         {\r
102                                 // ATTENTION: fixes on this code must be ported to\r
103                                 // var basePath in "core/loader.js".\r
104 \r
105                                 // Find out the editor directory path, based on its <script> tag.\r
106                                 var path = window.CKEDITOR_BASEPATH || '';\r
107 \r
108                                 if ( !path )\r
109                                 {\r
110                                         var scripts = document.getElementsByTagName( 'script' );\r
111 \r
112                                         for ( var i = 0 ; i < scripts.length ; i++ )\r
113                                         {\r
114                                                 var match = scripts[i].src.match( /(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?.js(?:\?.*)?$/i );\r
115 \r
116                                                 if ( match )\r
117                                                 {\r
118                                                         path = match[1];\r
119                                                         break;\r
120                                                 }\r
121                                         }\r
122                                 }\r
123 \r
124                                 // In IE (only) the script.src string is the raw valued entered in the\r
125                                 // HTML. Other browsers return the full resolved URL instead.\r
126                                 if ( path.indexOf('://') == -1 )\r
127                                 {\r
128                                         // Absolute path.\r
129                                         if ( path.indexOf( '/' ) === 0 )\r
130                                                 path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path;\r
131                                         // Relative path.\r
132                                         else\r
133                                                 path = location.href.match( /^[^\?]*\/(?:)/ )[0] + path;\r
134                                 }\r
135 \r
136                                 if ( !path )\r
137                                                 throw 'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.';\r
138 \r
139                                 return path;\r
140                         })(),\r
141 \r
142                         /**\r
143                          * Gets the full URL for CKEditor resources. By default, URLs\r
144                          * returned by this function contains a querystring parameter ("t")\r
145                          * set to the {@link CKEDITOR.timestamp} value.\r
146                          * It's possible to provide a custom implementation to this\r
147                          * function by setting a global variable named CKEDITOR_GETURL.\r
148                          * This global variable must be set "before" the editor script\r
149                          * loading. If the custom implementation returns nothing, the\r
150                          * default implementation is used.\r
151                          * @returns {String} The full URL.\r
152                          * @example\r
153                          * // e.g. http://www.example.com/ckeditor/skins/default/editor.css?t=87dm\r
154                          * alert( CKEDITOR.getUrl( 'skins/default/editor.css' ) );\r
155                          * @example\r
156                          * // e.g. http://www.example.com/skins/default/editor.css?t=87dm\r
157                          * alert( CKEDITOR.getUrl( '/skins/default/editor.css' ) );\r
158                          * @example\r
159                          * // e.g. http://www.somesite.com/skins/default/editor.css?t=87dm\r
160                          * alert( CKEDITOR.getUrl( 'http://www.somesite.com/skins/default/editor.css' ) );\r
161                          */\r
162                         getUrl : function( resource )\r
163                         {\r
164                                 // If this is not a full or absolute path.\r
165                                 if ( resource.indexOf('://') == -1 && resource.indexOf( '/' ) !== 0 )\r
166                                         resource = this.basePath + resource;\r
167 \r
168                                 // Add the timestamp, except for directories.\r
169                                 if ( this.timestamp && resource.charAt( resource.length - 1 ) != '/' )\r
170                                         resource += ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 't=' + this.timestamp;\r
171 \r
172                                 return resource;\r
173                         }\r
174                 };\r
175 \r
176                 // Make it possible to override the getUrl function with a custom\r
177                 // implementation pointing to a global named CKEDITOR_GETURL.\r
178                 var newGetUrl = window.CKEDITOR_GETURL;\r
179                 if ( newGetUrl )\r
180                 {\r
181                         var originalGetUrl = CKEDITOR.getUrl;\r
182                         CKEDITOR.getUrl = function ( resource )\r
183                         {\r
184                                 return newGetUrl.call( CKEDITOR, resource ) ||\r
185                                         originalGetUrl.call( CKEDITOR, resource );\r
186                         };\r
187                 }\r
188 \r
189                 return CKEDITOR;\r
190         })();\r
191 }\r
192 \r
193 // PACKAGER_RENAME( CKEDITOR )\r