CKEditor 4 - 无法添加Widget

时间:2014-10-24 01:31:38

标签: ckeditor

我正在创建一个简单的插件,将Richcombo添加到工具栏中,当点击下拉菜单中的某个选项时,该工具栏将插入小部件。

以下是代码:

CKEDITOR.plugins.add( 'myPlugin', {

    init : function( editor )
    {
        editor.widgets.add( 'widget1' );
        editor.ui.addRichCombo( 'richcombo1', {...} );  
    }

});

chrome > inspect element> console下, 它说:Uncaught TypeError: Cannot read property 'add' of undefined 我使用的是版本4.4.5

请帮助,没有人回复CKEditor的论坛。

1 个答案:

答案 0 :(得分:2)

您需要widget插件。否则editor.widgets对象不存在,因此出错。

CKEDITOR.plugins.add( 'myPlugin', {
    // Load the widget plugin.
    requires: 'widget',

    init : function( editor )
    {
        editor.widgets.add( 'widget1', {
            // Your widget definition...
        } );
    }

} );

有关详情,请参阅有关creating simple widget的教程。