1 /* 2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 /** 7 * @fileOverview Defines the {@link CKEDITOR.loader} objects, which is used to 8 * load core scripts and their dependencies from _source. 9 */ 10 11 if ( typeof CKEDITOR == 'undefined' ) 12 CKEDITOR = {}; 13 14 if ( !CKEDITOR.loader ) 15 { 16 /** 17 * Load core scripts and their dependencies from _source. 18 * @namespace 19 * @example 20 */ 21 CKEDITOR.loader = (function() 22 { 23 // Table of script names and their dependencies. 24 var scripts = 25 { 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/elementpath', 'core/dom/text', 'core/dom/range' ], 27 'core/ajax' : [ 'core/xml' ], 28 '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/tools' ], 29 'core/ckeditor_base' : [], 30 'core/ckeditor_basic' : [ 'core/editor_basic', 'core/env', 'core/event' ], 31 'core/command' : [], 32 'core/config' : [ 'core/ckeditor_base' ], 33 'core/dom' : [], 34 'core/dom/document' : [ 'core/dom','core/dom/element', 'core/dom/domobject', 'core/dom/window' ], 35 'core/dom/documentFragment' : [ 'core/dom/element' ], 36 'core/dom/element' : [ 'core/dom', 'core/dom/document', 'core/dom/domobject', 'core/dom/node', 'core/dom/nodelist', 'core/tools' ], 37 'core/dom/elementpath' : [ 'core/dom/element' ], 38 'core/dom/event' : [], 39 'core/dom/node' : [ 'core/dom/domobject', 'core/tools' ], 40 'core/dom/nodelist' : [ 'core/dom/node' ], 41 'core/dom/domobject' : [ 'core/dom/event' ], 42 'core/dom/domwalker' : [ 'core/dom/node', 'core/dom/element', 'core/dom/document' ], 43 'core/dom/range' : [ 'core/dom/document', 'core/dom/documentFragment', 'core/dom/element', 'core/dom/domwalker' ], 44 'core/dom/text' : [ 'core/dom/node', 'core/dom/domobject' ], 45 'core/dom/window' : [ 'core/dom/domobject' ], 46 'core/dtd' : [ 'core/tools' ], 47 'core/editor' : [ 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ], 48 'core/editor_basic' : [ 'core/event' ], 49 'core/env' : [], 50 'core/event' : [], 51 'core/focusmanager' : [], 52 'core/htmlparser' : [], 53 'core/htmlparser/comment' : [ 'core/htmlparser' ], 54 'core/htmlparser/element' : [ 'core/htmlparser', 'core/htmlparser/fragment' ], 55 'core/htmlparser/fragment' : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text' ], 56 'core/htmlparser/text' : [ 'core/htmlparser' ], 57 'core/imagecacher' : [ 'core/dom/element' ], 58 'core/lang' : [], 59 'core/plugins' : [ 'core/resourcemanager' ], 60 'core/resourcemanager' : [ 'core/scriptloader', 'core/tools' ], 61 'core/scriptloader' : [ 'core/dom/element', 'core/env' ], 62 'core/skins' : [ 'core/imagecacher', 'core/scriptloader' ], 63 'core/themes' : [ 'core/resourcemanager' ], 64 'core/tools' : [ 'core/env' ], 65 'core/ui' : [], 66 'core/xml' : [ 'core/env' ] 67 }; 68 69 var basePath = (function() 70 { 71 // This is a copy of CKEDITOR.basePath, but requires the script having 72 // "_source/core/loader.js". 73 if ( CKEDITOR && CKEDITOR.basePath ) 74 return CKEDITOR.basePath; 75 76 // Find out the editor directory path, based on its <script> tag. 77 var path = ''; 78 var scripts = document.getElementsByTagName( 'script' ); 79 80 for ( var i = 0 ; i < scripts.length ; i++ ) 81 { 82 var match = scripts[i].src.match( /(^|.*[\\\/])core\/loader.js(?:\?.*)?$/i ); 83 84 if ( match ) 85 { 86 path = match[1]; 87 break; 88 } 89 } 90 91 // In IE (only) the script.src string is the raw valued entered in the 92 // HTML. Other browsers return the full resolved URL instead. 93 if ( path.indexOf('://') == -1 ) 94 { 95 // Absolute path. 96 if ( path.indexOf( '/' ) === 0 ) 97 path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path; 98 // Relative path. 99 else 100 path = location.href.match( /^[^\?]*\// )[0] + path; 101 } 102 103 return path; 104 })(); 105 110 var timestamp = '9128'; 112 113 var getUrl = function( resource ) 114 { 115 if ( CKEDITOR && CKEDITOR.getUrl ) 116 return CKEDITOR.getUrl( resource ); 117 118 return basePath + resource + 119 ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 120 't=' + timestamp; 121 }; 122 123 /** @lends CKEDITOR.loader */ 124 return { 125 /** 126 * The list of loaded scripts in their loading order. 127 * @type Array 128 * @example 129 * // Alert the loaded script names. 130 * alert( <b>CKEDITOR.loader.loadedScripts</b> ); 131 */ 132 loadedScripts : [], 133 134 /** 135 * Loads a specific script, including its dependencies. This is not a 136 * synchronous loading, which means that the code the be loaded will 137 * not necessarily be available after this call. 138 * @example 139 * CKEDITOR.loader.load( 'core/dom/element' ); 140 */ 141 load : function( scriptName ) 142 { 143 // Check if the script has already been loaded. 144 if ( scriptName in this.loadedScripts ) 145 return; 146 147 // Get the script dependencies list. 148 var dependencies = scripts[ scriptName ]; 149 if ( !dependencies ) 150 throw 'The script name"' + scriptName + '" is not defined.'; 151 152 // Mark the script as loaded, even before really loading it, to 153 // avoid cross references recursion. 154 this.loadedScripts[ scriptName ] = true; 155 156 // Load all dependencies first. 157 for ( var i = 0 ; i < dependencies.length ; i++ ) 158 this.load( dependencies[ i ] ); 159 160 // Append this script to the list of loaded scripts. 161 this.loadedScripts.push( scriptName ); 162 163 var scriptSrc = getUrl( '_source/' + scriptName + '.js' ); 164 165 // Append the <script> element to the DOM. 166 if ( document.body ) 167 { 168 var script = document.createElement( 'script' ); 169 script.type = 'text/javascript'; 170 script.src = scriptSrc; 171 172 document.body.appendChild( script ); 173 } 174 else 175 document.write( '<script src="' + scriptSrc + '" type="text/javascript"><\/script>' ); 176 } 177 }; 178 })(); 179 } 180 181 // Check if any script has been defined for autoload. 182 if ( CKEDITOR._autoLoad ) 183 { 184 CKEDITOR.loader.load( CKEDITOR._autoLoad ); 185 delete CKEDITOR._autoLoad; 186 } 187