Index: /CKEditor/branches/prototype/_source/core/ckeditor.js =================================================================== --- /CKEditor/branches/prototype/_source/core/ckeditor.js (revision 2090) +++ /CKEditor/branches/prototype/_source/core/ckeditor.js (revision 2091) @@ -22,100 +22,28 @@ CKEDITOR.instances = {}; -(function() +// Overwrite the basic _replaceElement implementation with the definitive one. +CKEDITOR.replace._replaceElement = function( textarea, config ) { - // These function loads custom configuration files and cache the - // CKEDITOR.editorConfig functions defined on them, so there is no need to - // download them more than once for several instances. - var loadConfigLoaded = {}; - var loadConfig = function( editor ) - { - var customConfig = editor.config.customConfig; + // Encapsulates the original DOM textarea in a CKEDITOR.dom.element + // instance. + textarea = new CKEDITOR.dom.element( textarea ); + + // Create the editor instance. + CKEDITOR.add( new CKEDITOR.editor( textarea, config ) ); +}; - // Check if there is a custom config to load. - if ( !customConfig ) - return false; +CKEDITOR.add = function( editor ) +{ + var name = editor.name; - var loadedConfig = loadConfigLoaded[ customConfig ] || ( loadConfigLoaded[ customConfig ] = { editors : [] } ); + // Abort it there is already an instance with that name. + if ( CKEDITOR.instances[ name ] ) + return; - // If the custom config has already been downloaded, reuse it. - if ( loadedConfig.fn ) - { - // Call the cached CKEDITOR.editorConfig defined in the custom - // config file for the editor instance depending on it. - loadedConfig.fn.call( editor, editor ); + CKEDITOR.instances[ name ] = editor; - // If there is no other customConfig in the chain, fire the - // "configloaded" event. - if ( editor.config.customConfig == customConfig || !loadConfig( editor ) ) - editor.fireOnce( 'configloaded' ); - } - else - { - // Add the editor to the list of editors waiting for this config. - loadedConfig.editors.push( editor ); - - // Load the custom configuration file. - CKEDITOR.scriptLoader.load( customConfig, function() - { - // If the CKEDITOR.editorConfig function has been properly - // defined in the custom configuration file, cache it. - if ( CKEDITOR.editorConfig ) - loadedConfig.fn = CKEDITOR.editorConfig; - else - loadedConfig.fn = function(){}; - - delete CKEDITOR.editorConfig; - - CKEDITOR.tools.each( loadedConfig.editors, function( editor ) - { - // Call the load config again. This time the custom - // config is already cached and so it will get loaded. - loadConfig( editor ); - }); - - delete loadedConfig.editors; - } ); - } - - return true; - }; - - // Overwrite the basic _replaceElement implementation with the definitive one. - CKEDITOR.replace._replaceElement = function( textarea, config ) - { - var textarea = new CKEDITOR.dom.element( textarea ); - - // Create the editor instance. - var editor = new CKEDITOR.editor( textarea ); - - // Abort it there is already an instance with that name. - if ( CKEDITOR.instances[ editor.name ] ) - return; - - textarea.hide(); - - CKEDITOR.instances[ editor.name ] = editor; - - // Setup the lister for the "configloaded" event. - editor.on( 'configloaded', function() - { - // Overwrite the settings from the in-page config. - if ( config ) - CKEDITOR.tools.extend( editor.config, config, true ); - - // Fire the "instancecreated" event. - CKEDITOR.fire( 'instancecreated', editor.name, editor ); - }); - - // The instance config may override the customConfig setting to avoid - // loading the default ~/config.js file. - if ( config && config.customConfig != undefined ) - editor.config.customConfig = config.customConfig; - - // Load configs from the custom configuration files. - if ( !loadConfig( editor ) ) - editor.fireOnce( 'configloaded' ); - }; -})(); + CKEDITOR.fire( 'instancecreated', name, editor ); + editor.fireOnce( 'instancecreated' ); +}; // Set the status to "loading", which means that the main CKEDITOR object has Index: /CKEditor/branches/prototype/_source/core/editor.js =================================================================== --- /CKEditor/branches/prototype/_source/core/editor.js (revision 2090) +++ /CKEditor/branches/prototype/_source/core/editor.js (revision 2091) @@ -36,11 +36,91 @@ return CKEDITOR.instances[ name ] ? getNewName() : name; }; - + + // These function loads custom configuration files and cache the + // CKEDITOR.editorConfig functions defined on them, so there is no need to + // download them more than once for several instances. + var loadConfigLoaded = {}; + var loadConfig = function( editor ) + { + var customConfig = editor.config.customConfig; + + // Check if there is a custom config to load. + if ( !customConfig ) + return false; + + var loadedConfig = loadConfigLoaded[ customConfig ] || ( loadConfigLoaded[ customConfig ] = { editors : [] } ); + + // If the custom config has already been downloaded, reuse it. + if ( loadedConfig.fn ) + { + // Call the cached CKEDITOR.editorConfig defined in the custom + // config file for the editor instance depending on it. + loadedConfig.fn.call( editor, editor ); + + // If there is no other customConfig in the chain, fire the + // "configloaded" event. + if ( editor.config.customConfig == customConfig || !loadConfig( editor ) ) + editor.fireOnce( 'customconfigloaded' ); + } + else + { + // Add the editor to the list of editors waiting for this config. + loadedConfig.editors.push( editor ); + + // Load the custom configuration file. + CKEDITOR.scriptLoader.load( customConfig, function() + { + // If the CKEDITOR.editorConfig function has been properly + // defined in the custom configuration file, cache it. + if ( CKEDITOR.editorConfig ) + loadedConfig.fn = CKEDITOR.editorConfig; + else + loadedConfig.fn = function(){}; + + delete CKEDITOR.editorConfig; + + CKEDITOR.tools.each( loadedConfig.editors, function( editor ) + { + // Call the load config again. This time the custom + // config is already cached and so it will get loaded. + loadConfig( editor ); + }); + + delete loadedConfig.editors; + } ); + } + + return true; + }; + + var initConfig = function( editor, instanceConfig ) + { + // Setup the lister for the "customconfigloaded" event. + editor.on( 'customconfigloaded', function() + { + // Overwrite the settings from the in-page config. + if ( instanceConfig ) + CKEDITOR.tools.extend( editor.config, instanceConfig, true ); + + // Fire the "configloaded" event. + editor.fire( 'configloaded' ); + }); + + // The instance config may override the customConfig setting to avoid + // loading the default ~/config.js file. + if ( instanceConfig && instanceConfig.customConfig != undefined ) + editor.config.customConfig = instanceConfig.customConfig; + + // Load configs from the custom configuration files. + if ( !loadConfig( editor ) ) + editor.fireOnce( 'customconfigloaded' ); + }; + // Basic config class to inherit the default settings from CKEDITOR.config. var config = function() {} config.prototype = CKEDITOR.config; - - return function( element ) + + return function( element, instanceConfig ) { // Call the base constructor. @@ -49,7 +129,14 @@ this.element = element; this.name = element.getId() || element.getNameAtt() || getNewName(); - + // Get the default settings. this.config = new config(); + + // Call initConfig using events, to be sure that instancecreated is + // fired first. + this.on( 'instancecreated', function() + { + initConfig( this, instanceConfig ); + }); }; }()); @@ -64,5 +151,5 @@ return CKEDITOR.event.prototype.fire.call( this, eventName, data, this ); }, - + fireOnce : function( eventName, data ) { Index: /CKEditor/branches/prototype/_source/plugins/themes/default.js =================================================================== --- /CKEditor/branches/prototype/_source/plugins/themes/default.js (revision 2090) +++ /CKEditor/branches/prototype/_source/plugins/themes/default.js (revision 2091) @@ -22,7 +22,7 @@ CKEDITOR.theme.add( 'default', { - build : function { instance ) + build : function { editor ) { - + editor.element.hide(); } }); Index: /CKEditor/branches/prototype/_source/tests/core/_editor/custom_config_1.js =================================================================== --- /CKEditor/branches/prototype/_source/tests/core/_editor/custom_config_1.js (revision 2091) +++ /CKEditor/branches/prototype/_source/tests/core/_editor/custom_config_1.js (revision 2091) @@ -0,0 +1,27 @@ +/* + * CKEditor - The text editor for Internet - http://ckeditor.com + * Copyright (C) 2003-2008 Frederico Caldeira Knabben + * + * == BEGIN LICENSE == + * + * Licensed under the terms of any of the following licenses at your + * choice: + * + * - GNU General Public License Version 2 or later (the "GPL") + * http://www.gnu.org/licenses/gpl.html + * + * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") + * http://www.gnu.org/licenses/lgpl.html + * + * - Mozilla Public License Version 1.1 or later (the "MPL") + * http://www.mozilla.org/MPL/MPL-1.1.html + * + * == END LICENSE == + */ + +CKEDITOR.editorConfig = function( editor ) +{ + var config = editor.config; + config.customConfig = '_editor/custom_config_2.js'; + config.test_custom1 = 'Ok'; +}; Index: /CKEditor/branches/prototype/_source/tests/core/_editor/custom_config_2.js =================================================================== --- /CKEditor/branches/prototype/_source/tests/core/_editor/custom_config_2.js (revision 2091) +++ /CKEditor/branches/prototype/_source/tests/core/_editor/custom_config_2.js (revision 2091) @@ -0,0 +1,26 @@ +/* + * CKEditor - The text editor for Internet - http://ckeditor.com + * Copyright (C) 2003-2008 Frederico Caldeira Knabben + * + * == BEGIN LICENSE == + * + * Licensed under the terms of any of the following licenses at your + * choice: + * + * - GNU General Public License Version 2 or later (the "GPL") + * http://www.gnu.org/licenses/gpl.html + * + * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") + * http://www.gnu.org/licenses/lgpl.html + * + * - Mozilla Public License Version 1.1 or later (the "MPL") + * http://www.mozilla.org/MPL/MPL-1.1.html + * + * == END LICENSE == + */ + +CKEDITOR.editorConfig = function( editor ) +{ + var config = editor.config; + config.test_custom2 = 'Ok'; +}; Index: /CKEditor/branches/prototype/_source/tests/core/ckeditor.html =================================================================== --- /CKEditor/branches/prototype/_source/tests/core/ckeditor.html (revision 2090) +++ /CKEditor/branches/prototype/_source/tests/core/ckeditor.html (revision 2091) @@ -106,7 +106,4 @@ })() ); - - - //]]> Index: /CKEditor/branches/prototype/_source/tests/core/editor.html =================================================================== --- /CKEditor/branches/prototype/_source/tests/core/editor.html (revision 2091) +++ /CKEditor/branches/prototype/_source/tests/core/editor.html (revision 2091) @@ -0,0 +1,103 @@ + + +
+