2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview Defines the {@link CKEDITOR.loader} objects, which is used to
\r
8 * load core scripts and their dependencies from _source.
\r
11 if ( typeof CKEDITOR == 'undefined' )
\r
14 if ( !CKEDITOR.loader )
\r
17 * Load core scripts and their dependencies from _source.
\r
21 CKEDITOR.loader = (function()
\r
23 // Table of script names and their dependencies.
\r
26 'core/_bootstrap' : [ 'core/config', 'core/ckeditor', 'core/plugins', 'core/scriptloader', 'core/tools', /* The following are entries that we want to force loading at the end to avoid dependence recursion */ 'core/dom/comment', 'core/dom/elementpath', 'core/dom/text', 'core/dom/rangelist' ],
\r
27 'core/ckeditor' : [ 'core/ckeditor_basic', 'core/dom', 'core/dtd', 'core/dom/document', 'core/dom/element', 'core/editor', 'core/event', 'core/htmlparser', 'core/htmlparser/element', 'core/htmlparser/fragment', 'core/htmlparser/filter', 'core/htmlparser/basicwriter', 'core/tools' ],
\r
28 'core/ckeditor_base' : [],
\r
29 'core/ckeditor_basic' : [ 'core/editor_basic', 'core/env', 'core/event' ],
\r
30 'core/command' : [],
\r
31 'core/config' : [ 'core/ckeditor_base' ],
\r
33 'core/dom/comment' : [ 'core/dom/node' ],
\r
34 'core/dom/document' : [ 'core/dom', 'core/dom/domobject', 'core/dom/window' ],
\r
35 'core/dom/documentfragment' : [ 'core/dom/element' ],
\r
36 'core/dom/element' : [ 'core/dom', 'core/dom/document', 'core/dom/domobject', 'core/dom/node', 'core/dom/nodelist', 'core/tools' ],
\r
37 'core/dom/elementpath' : [ 'core/dom/element' ],
\r
38 'core/dom/event' : [],
\r
39 'core/dom/node' : [ 'core/dom/domobject', 'core/tools' ],
\r
40 'core/dom/nodelist' : [ 'core/dom/node' ],
\r
41 'core/dom/domobject' : [ 'core/dom/event' ],
\r
42 'core/dom/range' : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/walker' ],
\r
43 'core/dom/rangelist' : [ 'core/dom/range' ],
\r
44 'core/dom/text' : [ 'core/dom/node', 'core/dom/domobject' ],
\r
45 'core/dom/walker' : [ 'core/dom/node' ],
\r
46 'core/dom/window' : [ 'core/dom/domobject' ],
\r
47 'core/dtd' : [ 'core/tools' ],
\r
48 'core/editor' : [ 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],
\r
49 'core/editor_basic' : [ 'core/event' ],
\r
52 'core/focusmanager' : [],
\r
53 'core/htmlparser' : [],
\r
54 'core/htmlparser/comment' : [ 'core/htmlparser' ],
\r
55 'core/htmlparser/element' : [ 'core/htmlparser', 'core/htmlparser/fragment' ],
\r
56 'core/htmlparser/fragment' : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text', 'core/htmlparser/cdata' ],
\r
57 'core/htmlparser/text' : [ 'core/htmlparser' ],
\r
58 'core/htmlparser/cdata' : [ 'core/htmlparser' ],
\r
59 'core/htmlparser/filter' : [ 'core/htmlparser' ],
\r
60 'core/htmlparser/basicwriter': [ 'core/htmlparser' ],
\r
62 'core/plugins' : [ 'core/resourcemanager' ],
\r
63 'core/resourcemanager' : [ 'core/scriptloader', 'core/tools' ],
\r
64 'core/scriptloader' : [ 'core/dom/element', 'core/env' ],
\r
65 'core/skins' : [ 'core/scriptloader' ],
\r
66 'core/themes' : [ 'core/resourcemanager' ],
\r
67 'core/tools' : [ 'core/env' ],
\r
71 var basePath = (function()
\r
73 // This is a copy of CKEDITOR.basePath, but requires the script having
\r
74 // "_source/core/loader.js".
\r
75 if ( CKEDITOR && CKEDITOR.basePath )
\r
76 return CKEDITOR.basePath;
\r
78 // Find out the editor directory path, based on its <script> tag.
\r
80 var scripts = document.getElementsByTagName( 'script' );
\r
82 for ( var i = 0 ; i < scripts.length ; i++ )
\r
84 var match = scripts[i].src.match( /(^|.*?[\\\/])(?:_source\/)?core\/loader.js(?:\?.*)?$/i );
\r
93 // In IE (only) the script.src string is the raw valued entered in the
\r
94 // HTML. Other browsers return the full resolved URL instead.
\r
95 if ( path.indexOf('://') == -1 )
\r
98 if ( path.indexOf( '/' ) === 0 )
\r
99 path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path;
\r
102 path = location.href.match( /^[^\?]*\// )[0] + path;
\r
108 var timestamp = 'B49D5BN';
\r
110 var getUrl = function( resource )
\r
112 if ( CKEDITOR && CKEDITOR.getUrl )
\r
113 return CKEDITOR.getUrl( resource );
\r
115 return basePath + resource +
\r
116 ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) +
\r
120 var pendingLoad = [];
\r
122 /** @lends CKEDITOR.loader */
\r
125 * The list of loaded scripts in their loading order.
\r
128 * // Alert the loaded script names.
\r
129 * alert( <b>CKEDITOR.loader.loadedScripts</b> );
\r
131 loadedScripts : [],
\r
133 loadPending : function()
\r
135 var scriptName = pendingLoad.shift();
\r
140 var scriptSrc = getUrl( '_source/' + scriptName + '.js' );
\r
142 var script = document.createElement( 'script' );
\r
143 script.type = 'text/javascript';
\r
144 script.src = scriptSrc;
\r
146 function onScriptLoaded()
\r
148 // Append this script to the list of loaded scripts.
\r
149 CKEDITOR.loader.loadedScripts.push( scriptName );
\r
152 CKEDITOR.loader.loadPending();
\r
155 // We must guarantee the execution order of the scripts, so we
\r
156 // need to load them one by one. (#4145)
\r
157 // The following if/else block has been taken from the scriptloader core code.
\r
158 if ( typeof(script.onreadystatechange) !== "undefined" )
\r
161 script.onreadystatechange = function()
\r
163 if ( script.readyState == 'loaded' || script.readyState == 'complete' )
\r
165 script.onreadystatechange = null;
\r
173 script.onload = function()
\r
175 // Some browsers, such as Safari, may call the onLoad function
\r
176 // immediately. Which will break the loading sequence. (#3661)
\r
177 setTimeout( function() { onScriptLoaded( scriptName ); }, 0 );
\r
181 document.body.appendChild( script );
\r
185 * Loads a specific script, including its dependencies. This is not a
\r
186 * synchronous loading, which means that the code to be loaded will
\r
187 * not necessarily be available after this call.
\r
189 * CKEDITOR.loader.load( 'core/dom/element' );
\r
191 load : function( scriptName, defer )
\r
193 // Check if the script has already been loaded.
\r
194 if ( scriptName in this.loadedScripts )
\r
197 // Get the script dependencies list.
\r
198 var dependencies = scripts[ scriptName ];
\r
199 if ( !dependencies )
\r
200 throw 'The script name"' + scriptName + '" is not defined.';
\r
202 // Mark the script as loaded, even before really loading it, to
\r
203 // avoid cross references recursion.
\r
204 this.loadedScripts[ scriptName ] = true;
\r
206 // Load all dependencies first.
\r
207 for ( var i = 0 ; i < dependencies.length ; i++ )
\r
208 this.load( dependencies[ i ], true );
\r
210 var scriptSrc = getUrl( '_source/' + scriptName + '.js' );
\r
212 // Append the <script> element to the DOM.
\r
213 // If the page is fully loaded, we can't use document.write
\r
214 // but if the script is run while the body is loading then it's safe to use it
\r
215 // Unfortunately, Firefox <3.6 doesn't support document.readyState, so it won't get this improvement
\r
216 if ( document.body && (!document.readyState || document.readyState == 'complete') )
\r
218 pendingLoad.push( scriptName );
\r
221 this.loadPending();
\r
225 // Append this script to the list of loaded scripts.
\r
226 this.loadedScripts.push( scriptName );
\r
228 document.write( '<script src="' + scriptSrc + '" type="text/javascript"><\/script>' );
\r
235 // Check if any script has been defined for autoload.
\r
236 if ( CKEDITOR._autoLoad )
\r
238 CKEDITOR.loader.load( CKEDITOR._autoLoad );
\r
239 delete CKEDITOR._autoLoad;
\r