Class CKEDITOR.command
Represents a command that can be executed on an editor instance.
Extends
CKEDITOR.event.
Defined in: core/command.js.
Constructor Attributes | Constructor Name and Description |
---|---|
CKEDITOR.command(editor, commandDefinition)
Creates a command class instance.
|
Field Attributes | Field Name and Description |
---|---|
Indicates that the editor will get the focus before executing
the command.
|
|
The editor modes within which the command can be executed.
|
|
Indicates the previous command state.
|
|
Indicates the editor state.
|
|
Lists UI items that are associated to this command.
|
Method Attributes | Method Name and Description |
---|---|
disable()
Disables the command for execution.
|
|
enable()
Enables the command for execution.
|
|
exec(data)
Executes the command.
|
|
refresh()
Explicitly update the status of the command, by firing the CKEDITOR.command#event:refresh event,
as well as invoke the CKEDITOR.commandDefinition.prototype.refresh method if defined, this method
is to allow different parts of the editor code to contribute in command status resolution.
|
|
setState(newState)
Sets the command state.
|
|
Toggles the on/off (active/inactive) state of the command.
|
- Methods borrowed from class CKEDITOR.event:
- fire, fireOnce, hasListeners, on, removeListener
Event Attributes | Event Name and Description |
---|---|
Fired when the command state changes.
|
Class Detail
CKEDITOR.command(editor, commandDefinition)
Since:
3.0
Creates a command class instance.
var command = new CKEDITOR.command( editor, { exec : function( editor ) { alert( editor.document.getBody().getHtml() ); } });
- Parameters:
- {CKEDITOR.editor} editor
- The editor instance this command will be related to.
- {CKEDITOR.commandDefinition} commandDefinition
- The command definition.
Field Detail
{Boolean}
editorFocus
Since:
3.0
Indicates that the editor will get the focus before executing
the command.
// Do not force the editor to have focus when executing the command. command.editorFocus = false;
- Default Value:
- true
{Object}
modes
Since:
3.0
The editor modes within which the command can be executed. The
execution will have no action if the current mode is not listed
in this property.
// Enable the command in both WYSIWYG and Source modes. command.modes = { wysiwyg : 1, source : 1 };
// Enable the command in Source mode only. command.modes = { source : 1 };
- See:
- CKEDITOR.editor.prototype.mode
{Number}
previousState
Since:
3.0
Indicates the previous command state.
alert( command.previousState );
- See:
- #state
{Number}
state
Since:
3.0
Indicates the editor state. Possible values are:
- CKEDITOR.TRISTATE_DISABLED: the command is disabled. It's execution will have no effect. Same as disable.
- CKEDITOR.TRISTATE_ON: the command is enabled and currently active in the editor (for context sensitive commands, for example).
- CKEDITOR.TRISTATE_OFF: the command is enabled and currently inactive in the editor (for context sensitive commands, for example).
if ( command.state == CKEDITOR.TRISTATE_DISABLED ) alert( 'This command is disabled' );
{Array}
uiItems
Since:
3.0
Lists UI items that are associated to this command. This list can be
used to interact with the UI on command execution (by the execution code
itself, for example).
alert( 'Number of UI items associated to this command: ' + command.uiItems.length );
Method Detail
{Undefined}
disable()
Since:
3.0
Disables the command for execution. The command state (see
CKEDITOR.command.prototype.state) will be set to
CKEDITOR.TRISTATE_DISABLED.
command.disable(); command.exec(); // "false" - Nothing happens.
{Undefined}
enable()
Since:
3.0
Enables the command for execution. The command state (see
CKEDITOR.command.prototype.state) available before disabling it
is restored.
command.enable(); command.exec(); // Execute the command.
{Boolean}
exec(data)
Since:
3.0
Executes the command.
command.exec(); // The command gets executed.
- Parameters:
- {Object} data Optional
- Any data to pass to the command. Depends on the command implementation and requirements.
- Returns:
- {Boolean} A boolean indicating that the command has been successfully executed.
{Undefined}
refresh()
Since:
3.0
Explicitly update the status of the command, by firing the CKEDITOR.command#event:refresh event,
as well as invoke the CKEDITOR.commandDefinition.prototype.refresh method if defined, this method
is to allow different parts of the editor code to contribute in command status resolution.
NO EXAMPLE AVAILABLE
{Boolean}
setState(newState)
Since:
3.0
Sets the command state.
command.setState( CKEDITOR.TRISTATE_ON ); command.exec(); // Execute the command. command.setState( CKEDITOR.TRISTATE_DISABLED ); command.exec(); // "false" - Nothing happens. command.setState( CKEDITOR.TRISTATE_OFF ); command.exec(); // Execute the command.
- Parameters:
- {Number} newState
- The new state. See #state.
- Returns:
- {Boolean} Returns "true" if the command state changed.
{Undefined}
toggleState()
Since:
3.0
Toggles the on/off (active/inactive) state of the command. This is
mainly used internally by context sensitive commands.
command.toggleState();
Event Detail
state : <object>.on( 'state', function( e ){ ... } )
Since:
3.0
Fired when the command state changes.
command.on( 'state' , function( e ) { // Alerts the new state. alert( this.state ); });
- Parameters:
- {CKEDITOR.eventInfo} e
- The standard event object passed to event listeners.