当光标位于小部件的可编辑部分时,禁用ToolBar中的特定按钮? (CKEditor 4.5.11版)

时间:2017-10-04 20:44:44

标签: ckeditor ckeditor4.x

我想知道是否可以在“可编辑”中禁用工具栏中的特定小部件。小部件代码的一部分?我目前为小部件设置了以下代码。在这些选择器中,我不希望用户在ToolBar中添加特定的小部件。

this.editables = {
  content1: {
      selector: '.content1',
      allowedContent: this.allowedContent

    },
    content2: {
      selector: '.content2',
      allowedContent: this.allowedContent
    },
    content3: {
      selector: '.content3',
      allowedContent: this.allowedContent
    }
  };

我尝试添加以下逻辑,但它破坏了我的代码。

var oWidget= editor.getCommand('customWidget')
oWidget.setState(CKEDITOR.TRISTATE_DISABLED);

任何建议都会非常感激。

谢谢!

1 个答案:

答案 0 :(得分:0)

为此,您需要检查用户选择事件,以及是否在editable portion启用命令中进行选择。

像这样 -

CKEDITOR.instances["textarea"].on( 'selectionChange', function( evt ) {
    // get desired command from ckeditor 
    var myCommand = this.getCommand( 'CKEDITOR_COMMAND_NAME' );
    var mySelection = null;
    // check if something is selected
    var mySelection = this.getSelection().getNative() || this.window.$.getSelection() || this.document.$.selection;
    if (!mySelection) {
    // if not stay disable
        myCommand.disable();
    } else {
   //if yes enable command
    myCommand.enable();
    }

});
相关问题