2017-10-04 17 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(); 
    } 

}); 
相關問題