1 /* 2 * CKEditor - The text editor for Internet - http://ckeditor.com 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 */ 21 22 if ( typeof CKEDITOR == 'undefined' ) 23 CKEDITOR = {}; 24 25 /** 26 * Load core scripts and their dependencies from _source. 27 * @namespace 28 * @example 29 */ 30 CKEDITOR.loader = (function() 31 { 32 // Table of script names and their dependencies. 33 var scripts = 34 { 35 'core/_bootstrap' : [ 'core/config', 'core/ckeditor', 'core/scriptLoader', 'core/tools' ], 36 'core/ajax' : [ 'core/xml' ], 37 'core/ckeditor' : [ 'core/ajax', 'core/ckeditor_basic', 'core/dom', 'core/editor', 'core/dom/element', 'core/event', 'core/tools' ], 38 'core/ckeditor_base' : [], 39 'core/ckeditor_basic' : [ 'core/env', 'core/event' ], 40 'core/config' : [ 'core/ckeditor_base' ], 41 'core/dom' : [], 42 'core/dom/element' : [ 'core/dom' ], 43 'core/editor' : [ 'core/config', 'core/event', 'core/tools' ], 44 'core/env' : [], 45 'core/event' : [], 46 'core/scriptLoader' : [ 'core/dom/element', 'core/env' ], 47 'core/tools' : [ 'core/env' ], 48 'core/xml' : [ 'core/env' ] 49 }; 50 51 var loadedScripts = {}; 52 53 /** @lends CKEDITOR.loader */ 54 return { 55 basePath : (function() 56 { 57 // This is a copy of CKEDITOR.basePath, but requires the script having 58 // "_source/core/loader.js". 59 if ( CKEDITOR && CKEDITOR.basePath ) 60 return CKEDITOR.basePath; 61 62 // Find out the editor directory path, based on its <script> tag. 63 var path = ''; 64 var scripts = document.getElementsByTagName( 'script' ); 65 66 for ( var i = 0 ; i < scripts.length ; i++ ) 67 { 68 var match = scripts[i].src.match( /(^|.*[\\\/])_source\/core\/loader.js(?:\?.*)?$/i ); 69 70 if ( match ) 71 { 72 path = match[1]; 73 break; 74 } 75 } 76 77 // In IE (only) the script.src string is the raw valued entered in the 78 // HTML. Other browsers return the full resolved URL instead. 79 if ( path.indexOf('://') == -1 ) 80 { 81 // Absolute path. 82 if ( path.indexOf( '/' ) == 0 ) 83 path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path; 84 // Relative path. 85 else 86 path = location.href.match( /^[^\?]*\// )[0] + path; 87 } 88 89 return path; 90 })(), 91 92 /** 93 * The list of loaded scripts in the loading order. 94 * @type Array 95 */ 96 loadedScripts : [], 97 98 load : function( scriptName ) 99 { 100 // Check if the script has already been loaded. 101 if ( scriptName in loadedScripts ) 102 return; 103 104 // Get the script dependencies list. 105 var dependencies = scripts[ scriptName ]; 106 if ( !dependencies ) 107 throw 'The script name"' + scriptName + '" is not defined.'; 108 109 // Mark the script as loaded, even before really loading it, to 110 // avoid cross references recursion. 111 loadedScripts[ scriptName ] = true; 112 113 // Load all dependencies first. 114 for ( var i = 0 ; i < dependencies.length ; i++ ) 115 this.load( dependencies[ i ] ); 116 117 // Append this script to the list of loaded scripts. 118 this.loadedScripts.push( scriptName ); 119 120 // Append the <script> element to the DOM. 121 document.write( '<script src="' + this.basePath + '_source/' + scriptName + '.js" type="text/javascript"><\/script>' ); 122 } 123 }; 124 })(); 125 126 // Check if any script has been defined for autoload. 127 if ( CKEDITOR._autoLoad ) 128 { 129 CKEDITOR.loader.load( CKEDITOR._autoLoad ); 130 delete CKEDITOR._autoLoad; 131 } 132