diff options
Diffstat (limited to 'sources/core/ckeditor_base.js')
-rw-r--r-- | sources/core/ckeditor_base.js | 318 |
1 files changed, 318 insertions, 0 deletions
diff --git a/sources/core/ckeditor_base.js b/sources/core/ckeditor_base.js new file mode 100644 index 0000000..8c36b11 --- /dev/null +++ b/sources/core/ckeditor_base.js | |||
@@ -0,0 +1,318 @@ | |||
1 | /** | ||
2 | * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. | ||
3 | * For licensing, see LICENSE.md 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 | // Compressed code in ckeditor.js must be be updated on changes in the script. | ||
13 | // The Closure Compiler online service should be used when updating this manually: | ||
14 | // http://closure-compiler.appspot.com/ | ||
15 | |||
16 | // #### Raw code | ||
17 | // ATTENTION: read the above "Compressed Code" notes when changing this code. | ||
18 | |||
19 | if ( !window.CKEDITOR ) { | ||
20 | /** | ||
21 | * This is the API entry point. The entire CKEditor code runs under this object. | ||
22 | * @class CKEDITOR | ||
23 | * @singleton | ||
24 | */ | ||
25 | window.CKEDITOR = ( function() { | ||
26 | var basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i; | ||
27 | |||
28 | var CKEDITOR = { | ||
29 | |||
30 | /** | ||
31 | * A constant string unique for each release of CKEditor. Its value | ||
32 | * is used, by default, to build the URL for all resources loaded | ||
33 | * by the editor code, guaranteeing clean cache results when | ||
34 | * upgrading. | ||
35 | * | ||
36 | * **Note:** There is [a known issue where "icons.png" does not include | ||
37 | * timestamp](http://dev.ckeditor.com/ticket/10685) and might get cached. | ||
38 | * We are working on having it fixed. | ||
39 | * | ||
40 | * alert( CKEDITOR.timestamp ); // e.g. '87dm' | ||
41 | */ | ||
42 | timestamp: '', // %REMOVE_LINE% | ||
43 | /* // %REMOVE_LINE% | ||
44 | // The production implementation contains a fixed timestamp, unique | ||
45 | // for each release and generated by the releaser. | ||
46 | // (Base 36 value of each component of YYMMDDHH - 4 chars total - e.g. 87bm == 08071122) | ||
47 | timestamp: '%TIMESTAMP%', | ||
48 | // %REMOVE_LINE% */ | ||
49 | |||
50 | /** | ||
51 | * Contains the CKEditor version number. | ||
52 | * | ||
53 | * alert( CKEDITOR.version ); // e.g. 'CKEditor 3.4.1' | ||
54 | */ | ||
55 | version: '%VERSION%', | ||
56 | |||
57 | /** | ||
58 | * Contains the CKEditor revision number. | ||
59 | * The revision number is incremented automatically, following each | ||
60 | * modification to the CKEditor source code. | ||
61 | * | ||
62 | * alert( CKEDITOR.revision ); // e.g. '3975' | ||
63 | */ | ||
64 | revision: '%REV%', | ||
65 | |||
66 | /** | ||
67 | * A 3-digit random integer, valid for the entire life of the CKEDITOR object. | ||
68 | * | ||
69 | * alert( CKEDITOR.rnd ); // e.g. 319 | ||
70 | * | ||
71 | * @property {Number} | ||
72 | */ | ||
73 | rnd: Math.floor( Math.random() * ( 999 /*Max*/ - 100 /*Min*/ + 1 ) ) + 100 /*Min*/, | ||
74 | |||
75 | /** | ||
76 | * Private object used to hold core stuff. It should not be used outside of | ||
77 | * the API code as properties defined here may change at any time | ||
78 | * without notice. | ||
79 | * | ||
80 | * @private | ||
81 | */ | ||
82 | _: { | ||
83 | pending: [], | ||
84 | basePathSrcPattern: basePathSrcPattern | ||
85 | }, | ||
86 | |||
87 | /** | ||
88 | * Indicates the API loading status. The following statuses are available: | ||
89 | * | ||
90 | * * **unloaded**: the API is not yet loaded. | ||
91 | * * **basic_loaded**: the basic API features are available. | ||
92 | * * **basic_ready**: the basic API is ready to load the full core code. | ||
93 | * * **loaded**: the API can be fully used. | ||
94 | * | ||
95 | * Example: | ||
96 | * | ||
97 | * if ( CKEDITOR.status == 'loaded' ) { | ||
98 | * // The API can now be fully used. | ||
99 | * doSomething(); | ||
100 | * } else { | ||
101 | * // Wait for the full core to be loaded and fire its loading. | ||
102 | * CKEDITOR.on( 'load', doSomething ); | ||
103 | * CKEDITOR.loadFullCore && CKEDITOR.loadFullCore(); | ||
104 | * } | ||
105 | */ | ||
106 | status: 'unloaded', | ||
107 | |||
108 | /** | ||
109 | * The full URL for the CKEditor installation directory. | ||
110 | * It is possible to manually provide the base path by setting a | ||
111 | * global variable named `CKEDITOR_BASEPATH`. This global variable | ||
112 | * must be set **before** the editor script loading. | ||
113 | * | ||
114 | * alert( CKEDITOR.basePath ); // e.g. 'http://www.example.com/ckeditor/' | ||
115 | * | ||
116 | * @property {String} | ||
117 | */ | ||
118 | basePath: ( function() { | ||
119 | // Find out the editor directory path, based on its <script> tag. | ||
120 | var path = window.CKEDITOR_BASEPATH || ''; | ||
121 | |||
122 | if ( !path ) { | ||
123 | var scripts = document.getElementsByTagName( 'script' ); | ||
124 | |||
125 | for ( var i = 0; i < scripts.length; i++ ) { | ||
126 | var match = scripts[ i ].src.match( basePathSrcPattern ); | ||
127 | |||
128 | if ( match ) { | ||
129 | path = match[ 1 ]; | ||
130 | break; | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | // In IE (only) the script.src string is the raw value entered in the | ||
136 | // HTML source. Other browsers return the full resolved URL instead. | ||
137 | if ( path.indexOf( ':/' ) == -1 && path.slice( 0, 2 ) != '//' ) { | ||
138 | // Absolute path. | ||
139 | if ( path.indexOf( '/' ) === 0 ) | ||
140 | path = location.href.match( /^.*?:\/\/[^\/]*/ )[ 0 ] + path; | ||
141 | // Relative path. | ||
142 | else | ||
143 | path = location.href.match( /^[^\?]*\/(?:)/ )[ 0 ] + path; | ||
144 | } | ||
145 | |||
146 | if ( !path ) | ||
147 | throw 'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.'; | ||
148 | |||
149 | return path; | ||
150 | } )(), | ||
151 | |||
152 | /** | ||
153 | * Gets the full URL for CKEditor resources. By default, URLs | ||
154 | * returned by this function contain a querystring parameter ("t") | ||
155 | * set to the {@link CKEDITOR#timestamp} value. | ||
156 | * | ||
157 | * It is possible to provide a custom implementation of this | ||
158 | * function by setting a global variable named `CKEDITOR_GETURL`. | ||
159 | * This global variable must be set **before** the editor script | ||
160 | * loading. If the custom implementation returns nothing (`==null`), the | ||
161 | * default implementation is used. | ||
162 | * | ||
163 | * // e.g. 'http://www.example.com/ckeditor/skins/default/editor.css?t=87dm' | ||
164 | * alert( CKEDITOR.getUrl( 'skins/default/editor.css' ) ); | ||
165 | * | ||
166 | * // e.g. 'http://www.example.com/skins/default/editor.css?t=87dm' | ||
167 | * alert( CKEDITOR.getUrl( '/skins/default/editor.css' ) ); | ||
168 | * | ||
169 | * // e.g. 'http://www.somesite.com/skins/default/editor.css?t=87dm' | ||
170 | * alert( CKEDITOR.getUrl( 'http://www.somesite.com/skins/default/editor.css' ) ); | ||
171 | * | ||
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 | */ | ||
176 | getUrl: function( resource ) { | ||
177 | // If this is not a full or absolute path. | ||
178 | if ( resource.indexOf( ':/' ) == -1 && resource.indexOf( '/' ) !== 0 ) | ||
179 | resource = this.basePath + resource; | ||
180 | |||
181 | // Add the timestamp, except for directories. | ||
182 | if ( this.timestamp && resource.charAt( resource.length - 1 ) != '/' && !( /[&?]t=/ ).test( resource ) ) | ||
183 | resource += ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 't=' + this.timestamp; | ||
184 | |||
185 | return resource; | ||
186 | }, | ||
187 | |||
188 | /** | ||
189 | * Specify a function to execute when the DOM is fully loaded. | ||
190 | * | ||
191 | * If called after the DOM has been initialized, the function passed in will | ||
192 | * be executed immediately. | ||
193 | * | ||
194 | * @method | ||
195 | * @todo | ||
196 | */ | ||
197 | domReady: ( function() { | ||
198 | // Based on the original jQuery code (available under the MIT license, see LICENSE.md). | ||
199 | |||
200 | var callbacks = []; | ||
201 | |||
202 | function onReady() { | ||
203 | try { | ||
204 | // Cleanup functions for the document ready method | ||
205 | if ( document.addEventListener ) { | ||
206 | document.removeEventListener( 'DOMContentLoaded', onReady, false ); | ||
207 | executeCallbacks(); | ||
208 | } | ||
209 | // Make sure body exists, at least, in case IE gets a little overzealous. | ||
210 | else if ( document.attachEvent && document.readyState === 'complete' ) { | ||
211 | document.detachEvent( 'onreadystatechange', onReady ); | ||
212 | executeCallbacks(); | ||
213 | } | ||
214 | } catch ( er ) {} | ||
215 | } | ||
216 | |||
217 | function executeCallbacks() { | ||
218 | var i; | ||
219 | while ( ( i = callbacks.shift() ) ) | ||
220 | i(); | ||
221 | } | ||
222 | |||
223 | return function( fn ) { | ||
224 | callbacks.push( fn ); | ||
225 | |||
226 | // Catch cases where this is called after the | ||
227 | // browser event has already occurred. | ||
228 | if ( document.readyState === 'complete' ) | ||
229 | // Handle it asynchronously to allow scripts the opportunity to delay ready | ||
230 | setTimeout( onReady, 1 ); | ||
231 | |||
232 | // Run below once on demand only. | ||
233 | if ( callbacks.length != 1 ) | ||
234 | return; | ||
235 | |||
236 | // For IE>8, Firefox, Opera and Webkit. | ||
237 | if ( document.addEventListener ) { | ||
238 | // Use the handy event callback | ||
239 | document.addEventListener( 'DOMContentLoaded', onReady, false ); | ||
240 | |||
241 | // A fallback to window.onload, that will always work | ||
242 | window.addEventListener( 'load', onReady, false ); | ||
243 | |||
244 | } | ||
245 | // If old IE event model is used | ||
246 | else if ( document.attachEvent ) { | ||
247 | // ensure firing before onload, | ||
248 | // maybe late but safe also for iframes | ||
249 | document.attachEvent( 'onreadystatechange', onReady ); | ||
250 | |||
251 | // A fallback to window.onload, that will always work | ||
252 | window.attachEvent( 'onload', onReady ); | ||
253 | |||
254 | // If IE and not a frame | ||
255 | // continually check to see if the document is ready | ||
256 | // use the trick by Diego Perini | ||
257 | // http://javascript.nwbox.com/IEContentLoaded/ | ||
258 | var toplevel = false; | ||
259 | |||
260 | try { | ||
261 | toplevel = !window.frameElement; | ||
262 | } catch ( e ) {} | ||
263 | |||
264 | if ( document.documentElement.doScroll && toplevel ) { | ||
265 | scrollCheck(); | ||
266 | } | ||
267 | } | ||
268 | |||
269 | function scrollCheck() { | ||
270 | try { | ||
271 | document.documentElement.doScroll( 'left' ); | ||
272 | } catch ( e ) { | ||
273 | setTimeout( scrollCheck, 1 ); | ||
274 | return; | ||
275 | } | ||
276 | onReady(); | ||
277 | } | ||
278 | }; | ||
279 | |||
280 | } )() | ||
281 | }; | ||
282 | |||
283 | // Make it possible to override the "url" function with a custom | ||
284 | // implementation pointing to a global named CKEDITOR_GETURL. | ||
285 | var newGetUrl = window.CKEDITOR_GETURL; | ||
286 | if ( newGetUrl ) { | ||
287 | var originalGetUrl = CKEDITOR.getUrl; | ||
288 | CKEDITOR.getUrl = function( resource ) { | ||
289 | return newGetUrl.call( CKEDITOR, resource ) || originalGetUrl.call( CKEDITOR, resource ); | ||
290 | }; | ||
291 | } | ||
292 | |||
293 | return CKEDITOR; | ||
294 | } )(); | ||
295 | } | ||
296 | |||
297 | /** | ||
298 | * Function called upon loading a custom configuration file that can | ||
299 | * modify the editor instance configuration ({@link CKEDITOR.editor#config}). | ||
300 | * It is usually defined inside the custom configuration files that can | ||
301 | * include developer defined settings. | ||
302 | * | ||
303 | * // This is supposed to be placed in the config.js file. | ||
304 | * CKEDITOR.editorConfig = function( config ) { | ||
305 | * // Define changes to default configuration here. For example: | ||
306 | * config.language = 'fr'; | ||
307 | * config.uiColor = '#AADC6E'; | ||
308 | * }; | ||
309 | * | ||
310 | * @method editorConfig | ||
311 | * @param {CKEDITOR.config} config A configuration object containing the | ||
312 | * settings defined for a {@link CKEDITOR.editor} instance up to this | ||
313 | * function call. Note that not all settings may still be available. See | ||
314 | * [Configuration Loading Order](http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Setting_Configurations#Configuration_Loading_Order) | ||
315 | * for details. | ||
316 | */ | ||
317 | |||
318 | // PACKAGER_RENAME( CKEDITOR ) | ||