ckeditor 4 jQuery Adapter,如何添加自定义按钮?

时间:2015-01-15 10:25:54

标签: javascript jquery ckeditor

代码0:

$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'
});

[code 1]没关系,正常显示在工具栏上,但[code 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'
});

1 个答案:

答案 0 :(得分: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!' );
} );