Question

How can i enable or disable the paragraph button of CKEditor on selection of an image. I did not want to remove it completely. am currently using ckeditor version 4.4

Was it helpful?

Solution

Use editor.getCommand() + CKEDITOR.command API (enable and disable):

editor.getCommand( 'justifyleft' ).disable();
editor.getCommand( 'justifyleft' ).enable();

For example:

CKEDITOR.instances.editor1.on( 'selectionChange', function( evt ) {
    var jLeftCommand = this.getCommand( 'justifyleft' ),
        jRightCommand = this.getCommand( 'justifyright' );

    if ( evt.data.path.lastElement.is( 'img' ) ) { 
        jLeftCommand.disable();
        jRightCommand.disable();
    } else {
        jLeftCommand.enable();
        jRightCommand.enable();
    }
} );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top