|
153 | 153 | this.keystrokeHandler = new CKEDITOR.keystrokeHandler( this );
|
154 | 154 |
|
155 | 155 | // Make the editor update its command states on mode change.
|
156 |
| - this.on( 'mode', updateCommands ); |
157 | 156 | this.on( 'readOnly', updateCommands );
|
158 | 157 | this.on( 'selectionChange', updateCommandsContext );
|
159 | 158 |
|
160 | 159 | // Handle startup focus.
|
161 | 160 | this.on( 'instanceReady', function() {
|
| 161 | + updateCommands.call( this ); |
| 162 | + // First 'mode' event is fired before this 'instanceReady', |
| 163 | + // so to avoid updating commands twice, add this listener here. |
| 164 | + this.on( 'mode', updateCommands ); |
| 165 | + |
162 | 166 | this.config.startupFocus && this.focus();
|
163 |
| - }); |
| 167 | + } ); |
164 | 168 |
|
165 | 169 | CKEDITOR.fire( 'instanceCreated', null, this );
|
166 | 170 |
|
|
185 | 189 | }
|
186 | 190 |
|
187 | 191 | function updateCommands() {
|
188 |
| - var command, |
189 |
| - commands = this.commands, |
| 192 | + var commands = this.commands, |
190 | 193 | mode = this.mode;
|
191 | 194 |
|
192 | 195 | if ( !mode )
|
193 | 196 | return;
|
194 | 197 |
|
195 |
| - for ( var name in commands ) { |
196 |
| - command = commands[ name ]; |
197 |
| - command[ command.startDisabled ? 'disable' : this.readOnly && !command.readOnly ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ](); |
198 |
| - } |
| 198 | + for ( var name in commands ) |
| 199 | + updateCommand( this, commands[ name ] ); |
| 200 | + } |
| 201 | + |
| 202 | + function updateCommand( editor, cmd ) { |
| 203 | + cmd[ cmd.startDisabled ? 'disable' : editor.readOnly && !cmd.readOnly ? 'disable' : cmd.modes[ editor.mode ] ? 'enable' : 'disable' ](); |
199 | 204 | }
|
200 | 205 |
|
201 | 206 | function updateCommandsContext( ev ) {
|
|
585 | 590 | addCommand: function( commandName, commandDefinition ) {
|
586 | 591 | commandDefinition.name = commandName.toLowerCase();
|
587 | 592 | var cmd = new CKEDITOR.command( this, commandDefinition );
|
| 593 | + |
| 594 | + // Update command when added after editor has been already initialized. |
| 595 | + if ( this.status == 'ready' && this.mode ) |
| 596 | + updateCommand( this, cmd ); |
| 597 | + |
588 | 598 | return this.commands[ commandName ] = cmd;
|
589 | 599 | },
|
590 | 600 |
|
|
0 commit comments