2015-01-15 96 views
0

代码0:ckeditor 4 jQuery适配器,如何添加自定义按钮?

$editor.ckeditor(function() { 
    var editor = this; 
    editor.ui.add('MyButton', CKEDITOR.UI_BUTTON, { 
     label: 'My Button', 
     command: 'test' 
    }); 
}, {toolbar: [['MyButton']]}); 

代码1:

var editor = CKEDITOR.replace('editor', {toolbar: [['MyButton']]}); 
editor.ui.add('MyButton', CKEDITOR.UI_BUTTON, { 
    label: 'My Button', 
    command: 'test' 
}); 

[代码1]是OK,正常在工具栏显示,但[代码0]是不行的,如何使用jQuery Adapter添加自定义按钮?



更新[代码0]:

$editor.ckeditor(function() { 
    var editor = this; 
    editor.on('pluginsLoaded', function(event) { 
     editor.ui.add('MyButton', CKEDITOR.UI_BUTTON, { 
      label: 'My Button', 
      command: 'test' 
     }); 
    }); 
}, 
{ 
    customConfig: '/ckeditor-config.js' 
}); 

回答

3

使用pluginsLoaded事件(jsFiddle):

$('textarea').ckeditor({ 
     on: { 
      pluginsLoaded: function() { 
       this.ui.add('MyButton', CKEDITOR.UI_BUTTON, { 
        label: 'My Button', 
        command: 'test' 
       }); 

       console.log(this.name + ' plugins ready!'); 
      } 
     }, 
     toolbar: [['MyButton']] 
    }, 
    function(textarea) { 
     console.log(this.name + ' instance ready!'); 
}); 
+0

我不知道这一点,肯定比我的答案这么好我删除它。 – jazZRo

+0

你好oleq,我更新了[code 0],使用自定义配置js,然后仍然不适合我。 – CAM

相关问题