2017-10-04 58 views
0

我想知道是否可以禁用工具栏的小工具代码的'可编辑'部分中的特定小部件?我目前已经为小部件设置了下面的代码。在这些选择器中,我不希望用户在ToolBar中添加特定的小部件。当光标位于小部件的可编辑部分时,禁用ToolBar中的特定按钮? (CKEditor版本4.5.11)

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); 

任何意见将不胜感激。

谢谢!

回答

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(); 
    } 

}); 
相关问题