As a rule, the best way to create a trio in the style of a command button is similar to how it is done in the basicstyles plugin:
var style = new CKEDITOR.style( { ... } ); editor.attachStyleStateChange( style, function( state ) { !editor.readOnly && editor.getCommand( 'commandName' ).setState( state ); } ); editor.addCommand( 'commandName', new CKEDITOR.styleCommand( style ) ); editor.ui.addButton( 'buttonName', { label: 'buttonLabel', command: 'commandName' } );
This code will take care of everything - the command and button state will be updated in accordance with the selection changes. You can also easily get the status of a command:
editor.getCommand( 'commandName' ).state; // Returns on of CKEDITOR.TRISTATE_*.
However, if you want to directly query the state of the style, you can use the style.checkActive() method:
style.checkActive( editor.elementPath(), editor );
You do not need to create commands and buttons for this.
Edit
The CKEditor style system has its limitations. For example, you cannot have a variable font size in a style. This means that to check the current font size you need to do a quick search in the DOM:
function getFontSize() { var span = editor.elementPath().contains( isFontSizeSpan ); return span ? span.getStyle( 'font-size' ) : null; function isFontSizeSpan( el ) { return el.is( 'span' ) && el.getStyle( 'font-size' ); } }
Now just use this method in the editor#selectionChange event listener to update the reference value.
source share