CKEditor 4 Documentation

CKEDITOR.command

Mixins

Files

Represents a command that can be executed on an editor instance.

var command = new CKEDITOR.command( editor, {
    exec: function( editor ) {
        alert( editor.document.getBody().getHtml() );
    }
} );
Defined By

Properties

CKEDITOR.command
view source
: Boolean
Indicates that this command is sensible to the selection context. ...

Indicates that this command is sensible to the selection context. If true, the refresh method will be called for this command on the CKEDITOR.editor.selectionChange event.

Defaults to: false

CKEDITOR.command
view source
: Boolean
Indicates that the editor will get the focus before executing the command. ...

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;

Defaults to: true

CKEDITOR.command
view source
: Object
The editor modes within which the command can be executed. ...

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 };

CKEDITOR.editor.mode

Defaults to: {wysiwyg: 1}

CKEDITOR.command
view source
: Number
Indicates the previous command state. ...

Indicates the previous command state.

alert( command.previousState );state
CKEDITOR.command
view source
: Number
Indicates the editor state. ...

Indicates the editor state. Possible values are:

Do not set this property directly, using the setState method instead.

if ( command.state == CKEDITOR.TRISTATE_DISABLED )
    alert( 'This command is disabled' );

Defaults to: CKEDITOR.TRISTATE_DISABLED

CKEDITOR.command
view source
: Array
Lists UI items that are associated to this command. ...

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 );

Defaults to: []

Defined By

Methods

CKEDITOR.command
view source
new( editor, commandDefinition ) : CKEDITOR.command
Creates a command class instance. ...

Creates a command class instance.

Parameters

Returns

Overrides: CKEDITOR.event.constructor

Register event handler under the capturing stage on supported target. ...

Register event handler under the capturing stage on supported target.

CKEDITOR.command
view source
( [noCache] ) : Boolean
Checks whether this command is allowed by the active allowed content filter (CKEDITOR.editor.activeFilter). ...

Checks whether this command is allowed by the active allowed content filter (CKEDITOR.editor.activeFilter). This means that if command implements CKEDITOR.feature interface it will be tested by the CKEDITOR.filter.checkFeature method.

Available since: 4.1

Parameters

  • noCache : Boolean (optional)

    Skip cache for example due to active filter change. Since CKEditor 4.2.

Returns

  • Boolean

    Whether this command is allowed.

Predefine some intrinsic properties on a specific event name. ...

Predefine some intrinsic properties on a specific event name.

Parameters

  • name : String

    The event name

  • meta : Object
    • errorProof : (optional)

      Whether the event firing should catch error thrown from a per listener call.

      Defaults to: false

CKEDITOR.command
view source
( )
Disables the command for execution. ...

Disables the command for execution. The command state (see state) will be set to CKEDITOR.TRISTATE_DISABLED.

command.disable();
command.exec(); // "false" - Nothing happens.
CKEDITOR.command
view source
( )
Enables the command for execution. ...

Enables the command for execution. The command state (see state) available before disabling it is restored.

command.enable();
command.exec(); // Execute the command.
CKEDITOR.command
view source
( [data] ) : Boolean
Executes the command. ...

Executes the command.

command.exec(); // The command gets executed.

Parameters

  • data : Object (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.

( eventName, [data], [editor] ) : Boolean/Object
Fires an specific event in the object. ...

Fires an specific event in the object. All registered listeners are called at this point.

someObject.on( 'someEvent', function() { ... } );
someObject.on( 'someEvent', function() { ... } );
someObject.fire( 'someEvent' );             // Both listeners are called.

someObject.on( 'someEvent', function( event ) {
    alert( event.data );                    // 'Example'
} );
someObject.fire( 'someEvent', 'Example' );

Parameters

Returns

  • Boolean/Object

    A boolean indicating that the event is to be canceled, or data returned by one of the listeners.

( eventName, [data], [editor] ) : Boolean/Object
Fires an specific event in the object, releasing all listeners registered to that event. ...

Fires an specific event in the object, releasing all listeners registered to that event. The same listeners are not called again on successive calls of it or of fire.

someObject.on( 'someEvent', function() { ... } );
someObject.fire( 'someEvent' );         // Above listener called.
someObject.fireOnce( 'someEvent' );     // Above listener called.
someObject.fire( 'someEvent' );         // No listeners called.

Parameters

Returns

  • Boolean/Object

    A booloan indicating that the event is to be canceled, or data returned by one of the listeners.

Checks if there is any listener registered to a given event. ...

Checks if there is any listener registered to a given event.

var myListener = function() { ... };
someObject.on( 'someEvent', myListener );
alert( someObject.hasListeners( 'someEvent' ) );    // true
alert( someObject.hasListeners( 'noEvent' ) );      // false

Parameters

  • eventName : String

    The event name.

Returns

  • Boolean
( eventName, listenerFunction, [scopeObj], [listenerData], [priority] ) : Object
Registers a listener to a specific event in the current object. ...

Registers a listener to a specific event in the current object.

someObject.on( 'someEvent', function() {
    alert( this == someObject );        // true
} );

someObject.on( 'someEvent', function() {
    alert( this == anotherObject );     // true
}, anotherObject );

someObject.on( 'someEvent', function( event ) {
    alert( event.listenerData );        // 'Example'
}, null, 'Example' );

someObject.on( 'someEvent', function() { ... } );                       // 2nd called
someObject.on( 'someEvent', function() { ... }, null, null, 100 );      // 3rd called
someObject.on( 'someEvent', function() { ... }, null, null, 1 );        // 1st called

Parameters

  • eventName : String

    The event name to which listen.

  • listenerFunction : Function

    The function listening to the event. A single CKEDITOR.eventInfo object instanced is passed to this function containing all the event data.

  • scopeObj : Object (optional)

    The object used to scope the listener call (the this object). If omitted, the current object is used.

  • listenerData : Object (optional)

    Data to be sent as the CKEDITOR.eventInfo.listenerData when calling the listener.

  • priority : Number (optional)

    The listener priority. Lower priority listeners are called first. Listeners with the same priority value are called in registration order.

    Defaults to: 10

Returns

  • Object

    An object containing the removeListener function, which can be used to remove the listener at any time.

Similiar with on but the listener will be called only once upon the next event firing. ...

Similiar with on but the listener will be called only once upon the next event firing.

CKEDITOR.event.on

CKEDITOR.command
view source
( editor, path )
Explicitly update the status of the command, by firing the refresh event, as well as invoke the CKEDITOR.commandDefin...

Explicitly update the status of the command, by firing the refresh event, as well as invoke the CKEDITOR.commandDefinition.refresh method if defined, this method is to allow different parts of the editor code to contribute in command status resolution.

Parameters

Remove all existing listeners on this object, for cleanup purpose. ...

Remove all existing listeners on this object, for cleanup purpose.

( eventName, listenerFunction )
Unregisters a listener function from being called at the specified event. ...

Unregisters a listener function from being called at the specified event. No errors are thrown if the listener has not been registered previously.

var myListener = function() { ... };
someObject.on( 'someEvent', myListener );
someObject.fire( 'someEvent' );                 // myListener called.
someObject.removeListener( 'someEvent', myListener );
someObject.fire( 'someEvent' );                 // myListener not called.

Parameters

  • eventName : String

    The event name.

  • listenerFunction : Function

    The listener function to unregister.

CKEDITOR.command
view source
( newState ) : Boolean
Sets the command state. ...

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

  • newState : Number

    The new state. See state.

Returns

  • Boolean

    Returns true if the command state changed.

CKEDITOR.command
view source
( )
Toggles the on/off (active/inactive) state of the command. ...

Toggles the on/off (active/inactive) state of the command. This is mainly used internally by context sensitive commands.

command.toggleState();
Defined By

Events

CKEDITOR.command
view source
( evt )
...

Parameters

CKEDITOR.command
view source
( evt )
Fired when the command state changes. ...

Fired when the command state changes.

command.on( 'state', function() {
    // Alerts the new state.
    alert( this.state );
} );

Parameters