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 CKEDITOR.instances = {}; 23 24 (function() 25 { 26 // These function loads custom configuration files and cache the 27 // CKEDITOR.editorConfig functions defined on them, so there is no need to 28 // download them more than once for several instances. 29 var loadConfigLoaded = {}; 30 var loadConfig = function( editor ) 31 { 32 var customConfig = editor.config.customConfig; 33 34 // Check if there is a custom config to load. 35 if ( !customConfig ) 36 return false; 37 38 var loadedConfig = loadConfigLoaded[ customConfig ] || ( loadConfigLoaded[ customConfig ] = { editors : [] } ); 39 40 // If the custom config has already been downloaded, reuse it. 41 if ( loadedConfig.fn ) 42 { 43 // Call the cached CKEDITOR.editorConfig defined in the custom 44 // config file for the editor instance depending on it. 45 loadedConfig.fn.call( editor, editor ); 46 47 // If there is no other customConfig in the chain, fire the 48 // "configloaded" event. 49 if ( editor.config.customConfig == customConfig || !loadConfig( editor ) ) 50 editor.fireOnce( 'configloaded' ); 51 } 52 else 53 { 54 // Add the editor to the list of editors waiting for this config. 55 loadedConfig.editors.push( editor ); 56 57 // Load the custom configuration file. 58 CKEDITOR.scriptLoader.load( customConfig, function() 59 { 60 // If the CKEDITOR.editorConfig function has been properly 61 // defined in the custom configuration file, cache it. 62 if ( CKEDITOR.editorConfig ) 63 loadedConfig.fn = CKEDITOR.editorConfig; 64 else 65 loadedConfig.fn = function(){}; 66 67 delete CKEDITOR.editorConfig; 68 69 CKEDITOR.tools.each( loadedConfig.editors, function( editor ) 70 { 71 // Call the load config again. This time the custom 72 // config is already cached and so it will get loaded. 73 loadConfig( editor ); 74 }); 75 76 delete loadedConfig.editors; 77 } ); 78 } 79 80 return true; 81 }; 82 83 // Overwrite the basic _replaceElement implementation with the definitive one. 84 CKEDITOR.replace._replaceElement = function( textarea, config ) 85 { 86 var textarea = new CKEDITOR.dom.element( textarea ); 87 textarea.hide(); 88 89 // Create the editor instance. 90 var editor = new CKEDITOR.editor( textarea ); 91 CKEDITOR.instances[ editor.name ] = editor; 92 93 // Setup the lister for the "configloaded" event. 94 editor.on( 'configloaded', function() 95 { 96 // Overwrite the settings from the in-page config. 97 if ( config ) 98 CKEDITOR.tools.extend( editor.config, config, true ); 99 100 // Fire the "instancecreated" event. 101 CKEDITOR.fire( 'instancecreated', editor.name, editor ); 102 }); 103 104 // The instance config may override the customConfig setting to avoid 105 // loading the default ~/config.js file. 106 if ( config && config.customConfig != undefined ) 107 editor.config.customConfig = config.customConfig; 108 109 // Load configs from the custom configuration files. 110 if ( !loadConfig( editor ) ) 111 editor.fireOnce( 'configloaded' ); 112 }; 113 })(); 114 115 // Set the status to "loading", which means that the main CKEDITOR object has 116 // been created, and the rest is getting loaded. 117 CKEDITOR.status = 'loading'; 118 119 // Load the bootstrap script. 120 CKEDITOR.loader.load( 'core/_bootstrap' ); 121