Skip to content

Commit

Permalink
Simplfied the code updating commands so they are correctly updated in…
Browse files Browse the repository at this point in the history
… all cases.
  • Loading branch information
Reinmar committed Apr 2, 2013
1 parent 9e3ac8e commit 3332ea4
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions core/editor.js
Expand Up @@ -160,10 +160,6 @@

// Handle startup focus.
this.on( 'instanceReady', function( event ) {
// #10103: Update commands which were added after first 'mode' event and before
// instanceReady. Commands added later will be instantly updated.
updateCommands.call( this, event );

this.config.startupFocus && this.focus();
} );

Expand All @@ -189,31 +185,13 @@
return name;
}

var updateCommands = ( function() {
var startupCommands;

return function( event ) {
var commands = this.commands,
mode = this.mode;

if ( !mode )
return;

// Cache all the commands names that are present since the very beginning
// of editor's life. They will be used as a reference to determine which commands
// have been created afterwards (#10249).
if ( !startupCommands )
startupCommands = CKEDITOR.tools.objectKeys( commands );
function updateCommands() {
var commands = this.commands,
name;

// If updateCommands() is called on instanceReady, update all the *new commands* that
// emerged *after* the standard command definition phase but before this instanceReady.
// Otherwise, e.g. when called on mode or readOnly, update all the available commands (#10249).
for ( var name in commands ) {
if ( event.name == 'instanceReady' ? !~CKEDITOR.tools.indexOf( startupCommands, name ) : true )
updateCommand( this, commands[ name ] );
}
}
})();
for ( name in commands )
updateCommand( this, commands[ name ] );
}

function updateCommand( editor, cmd ) {
cmd[ cmd.startDisabled ? 'disable' : editor.readOnly && !cmd.readOnly ? 'disable' : cmd.modes[ editor.mode ] ? 'enable' : 'disable' ]();
Expand Down Expand Up @@ -615,8 +593,12 @@
commandDefinition.name = commandName.toLowerCase();
var cmd = new CKEDITOR.command( this, commandDefinition );

// Update command when added after editor has been already initialized.
if ( this.status == 'ready' && this.mode )
// Update command when mode is set.
// This guarantees that commands added before first editor#mode
// aren't immediately updated, but waits for editor#mode and that
// commands added later are immediately refreshed, even when added
// before instanceReady. #10103, #10249
if ( this.mode )
updateCommand( this, cmd );

return this.commands[ commandName ] = cmd;
Expand Down

0 comments on commit 3332ea4

Please sign in to comment.