JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
ded7e9e08a77da2b79010895246f615e28e37008
[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.2',rev:'6041',_:{},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          * @name CKEDITOR\r
24          * @namespace This is the API entry point. The entire CKEditor code runs under this object.\r
25          * @example\r
26          */\r
27         window.CKEDITOR = (function()\r
28         {\r
29                 var CKEDITOR =\r
30                 /** @lends CKEDITOR */\r
31                 {\r
32 \r
33                         /**\r
34                          * A constant string unique for each release of CKEditor. Its value\r
35                          * is used, by default, to build the URL for all resources loaded\r
36                          * by the editor code, guaranteing clean cache results when\r
37                          * upgrading.\r
38                          * @type String\r
39                          * @example\r
40                          * alert( CKEDITOR.timestamp );  // e.g. '87dm'\r
41                          */\r
42                         // The production implementation contains a fixed timestamp, unique\r
43                         // for each release, generated by the releaser.\r
44                         // (Base 36 value of each component of YYMMDDHH - 4 chars total - e.g. 87bm == 08071122)\r
45                         timestamp : 'AA4E4NT',\r
46 \r
47                         /**\r
48                          * Contains the CKEditor version number.\r
49                          * @type String\r
50                          * @example\r
51                          * alert( CKEDITOR.version );  // e.g. 'CKEditor 3.4.1'\r
52                          */\r
53                         version : '3.4.2',\r
54 \r
55                         /**\r
56                          * Contains the CKEditor revision number.\r
57                          * The revision number is incremented automatically, following each\r
58                          * modification to the CKEditor source code.\r
59                          * @type String\r
60                          * @example\r
61                          * alert( CKEDITOR.revision );  // e.g. '3975'\r
62                          */\r
63                         revision : '6041',\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.<br />\r
146                          * <br />\r
147                          * It's possible to provide a custom implementation to this\r
148                          * function by setting a global variable named CKEDITOR_GETURL.\r
149                          * This global variable must be set "before" the editor script\r
150                          * loading. If the custom implementation returns nothing (==null), the\r
151                          * default implementation is used.\r
152                          * @param {String} resource The resource to which get the full URL.\r
153                          *              It may be a full, absolute or relative URL.\r
154                          * @returns {String} The full URL.\r
155                          * @example\r
156                          * // e.g. http://www.example.com/ckeditor/skins/default/editor.css?t=87dm\r
157                          * alert( CKEDITOR.getUrl( 'skins/default/editor.css' ) );\r
158                          * @example\r
159                          * // e.g. http://www.example.com/skins/default/editor.css?t=87dm\r
160                          * alert( CKEDITOR.getUrl( '/skins/default/editor.css' ) );\r
161                          * @example\r
162                          * // e.g. http://www.somesite.com/skins/default/editor.css?t=87dm\r
163                          * alert( CKEDITOR.getUrl( 'http://www.somesite.com/skins/default/editor.css' ) );\r
164                          */\r
165                         getUrl : function( resource )\r
166                         {\r
167                                 // If this is not a full or absolute path.\r
168                                 if ( resource.indexOf('://') == -1 && resource.indexOf( '/' ) !== 0 )\r
169                                         resource = this.basePath + resource;\r
170 \r
171                                 // Add the timestamp, except for directories.\r
172                                 if ( this.timestamp && resource.charAt( resource.length - 1 ) != '/' && !(/[&?]t=/).test( resource ) )\r
173                                         resource += ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 't=' + this.timestamp;\r
174 \r
175                                 return resource;\r
176                         }\r
177                 };\r
178 \r
179                 // Make it possible to override the getUrl function with a custom\r
180                 // implementation pointing to a global named CKEDITOR_GETURL.\r
181                 var newGetUrl = window.CKEDITOR_GETURL;\r
182                 if ( newGetUrl )\r
183                 {\r
184                         var originalGetUrl = CKEDITOR.getUrl;\r
185                         CKEDITOR.getUrl = function ( resource )\r
186                         {\r
187                                 return newGetUrl.call( CKEDITOR, resource ) ||\r
188                                         originalGetUrl.call( CKEDITOR, resource );\r
189                         };\r
190                 }\r
191 \r
192                 return CKEDITOR;\r
193         })();\r
194 }\r
195 \r
196 // PACKAGER_RENAME( CKEDITOR )\r