Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporary disable button on ckeditor

Tags:

ckeditor

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

like image 731
user3603292 Avatar asked Sep 11 '26 00:09

user3603292


1 Answers

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();
    }
} );
like image 55
oleq Avatar answered Sep 21 '26 01:09

oleq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!