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