Brian
Brian

Reputation: 31292

CKEditor - detect which buttons are pressed

When I need to edit existing text stored in the database, some buttons on the CKeditor toolbar are pressed as they already have some styles.

For instance, if I have the following text in my database:

<strong>asdf</strong>

when I edit this text, the "bold" button is pressed.

I need to set bulletedlist clicked as the default setting of my editor. I listen to the instanceReady event and use execCommand('bulletedlist') when the event is on to achieve my goal:

CKEDITOR.on( 'instanceReady',function(ev) {
  ev.editor.execCommand( 'bulletedlist' );
} );

however, if the text is already bulleted, calling execCommand('bulletedlist') will cancel the bulleted style. I need to know which buttons are pressed when users start editing the text, so I can prevent canceling the default style. How can I achieve this?

Upvotes: 0

Views: 569

Answers (1)

Reinmar
Reinmar

Reputation: 22023

To query command state you need to use:

editor.getCommand( 'bulletedlist' ).state;

It will return one of:

Upvotes: 1

Related Questions