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/htmlparser/filter', 'core/htmlparser/basicwriter', '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/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', 'core/dom/walker' ], 44 'core/dom/text' : [ 'core/dom/node', 'core/dom/domobject' ], 45 'core/dom/walker' : [ 'core/dom/node' ], 46 'core/dom/window' : [ 'core/dom/domobject' ], 47 'core/dtd' : [ 'core/tools' ], 48 'core/editor' : [ 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ], 49 'core/editor_basic' : [ 'core/event' ], 50 'core/env' : [], 51 'core/event' : [], 52 'core/focusmanager' : [], 53 'core/htmlparser' : [], 54 'core/htmlparser/comment' : [ 'core/htmlparser' ], 55 'core/htmlparser/element' : [ 'core/htmlparser', 'core/htmlparser/fragment' ], 56 'core/htmlparser/fragment' : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text', 'core/htmlparser/cdata' ], 57 'core/htmlparser/text' : [ 'core/htmlparser' ], 58 'core/htmlparser/cdata' : [ 'core/htmlparser' ], 59 'core/htmlparser/filter' : [ 'core/htmlparser' ], 60 'core/htmlparser/basicwriter': [ 'core/htmlparser' ], 61 'core/imagecacher' : [ 'core/dom/element' ], 62 'core/lang' : [], 63 'core/plugins' : [ 'core/resourcemanager' ], 64 'core/resourcemanager' : [ 'core/scriptloader', 'core/tools' ], 65 'core/scriptloader' : [ 'core/dom/element', 'core/env' ], 66 'core/skins' : [ 'core/imagecacher', 'core/scriptloader' ], 67 'core/themes' : [ 'core/resourcemanager' ], 68 'core/tools' : [ 'core/env' ], 69 'core/ui' : [], 70 'core/xml' : [ 'core/env' ] 71 }; 72 73 var basePath = (function() 74 { 75 // This is a copy of CKEDITOR.basePath, but requires the script having 76 // "_source/core/loader.js". 77 if ( CKEDITOR && CKEDITOR.basePath ) 78 return CKEDITOR.basePath; 79 80 // Find out the editor directory path, based on its <script> tag. 81 var path = ''; 82 var scripts = document.getElementsByTagName( 'script' ); 83 84 for ( var i = 0 ; i < scripts.length ; i++ ) 85 { 86 var match = scripts[i].src.match( /(^|.*[\\\/])core\/loader.js(?:\?.*)?$/i ); 87 88 if ( match ) 89 { 90 path = match[1]; 91 break; 92 } 93 } 94 95 // In IE (only) the script.src string is the raw valued entered in the 96 // HTML. Other browsers return the full resolved URL instead. 97 if ( path.indexOf('://') == -1 ) 98 { 99 // Absolute path. 100 if ( path.indexOf( '/' ) === 0 ) 101 path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path; 102 // Relative path. 103 else 104 path = location.href.match( /^[^\?]*\// )[0] + path; 105 } 106 107 return path; 108 })(); 109 114 var timestamp = '95MI'; 116 117 var getUrl = function( resource ) 118 { 119 if ( CKEDITOR && CKEDITOR.getUrl ) 120 return CKEDITOR.getUrl( resource ); 121 122 return basePath + resource + 123 ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 124 't=' + timestamp; 125 }; 126 127 /** @lends CKEDITOR.loader */ 128 return { 129 /** 130 * The list of loaded scripts in their loading order. 131 * @type Array 132 * @example 133 * // Alert the loaded script names. 134 * alert( <b>CKEDITOR.loader.loadedScripts</b> ); 135 */ 136 loadedScripts : [], 137 138 /** 139 * Loads a specific script, including its dependencies. This is not a 140 * synchronous loading, which means that the code the be loaded will 141 * not necessarily be available after this call. 142 * @example 143 * CKEDITOR.loader.load( 'core/dom/element' ); 144 */ 145 load : function( scriptName ) 146 { 147 // Check if the script has already been loaded. 148 if ( scriptName in this.loadedScripts ) 149 return; 150 151 // Get the script dependencies list. 152 var dependencies = scripts[ scriptName ]; 153 if ( !dependencies ) 154 throw 'The script name"' + scriptName + '" is not defined.'; 155 156 // Mark the script as loaded, even before really loading it, to 157 // avoid cross references recursion. 158 this.loadedScripts[ scriptName ] = true; 159 160 // Load all dependencies first. 161 for ( var i = 0 ; i < dependencies.length ; i++ ) 162 this.load( dependencies[ i ] ); 163 164 // Append this script to the list of loaded scripts. 165 this.loadedScripts.push( scriptName ); 166 167 var scriptSrc = getUrl( '_source/' + scriptName + '.js' ); 168 169 // Append the <script> element to the DOM. 170 if ( document.body ) 171 { 172 var script = document.createElement( 'script' ); 173 script.type = 'text/javascript'; 174 script.src = scriptSrc; 175 176 document.body.appendChild( script ); 177 } 178 else 179 document.write( '<script src="' + scriptSrc + '" type="text/javascript"><\/script>' ); 180 } 181 }; 182 })(); 183 } 184 185 // Check if any script has been defined for autoload. 186 if ( CKEDITOR._autoLoad ) 187 { 188 CKEDITOR.loader.load( CKEDITOR._autoLoad ); 189 delete CKEDITOR._autoLoad; 190 } 191