CKEditor错误创建对话框

时间:2017-05-11 02:03:35

标签: javascript ckeditor

我有以下测试脚本:



    var field = {id: "html1"};
    var editor = CKEDITOR.replace(field.id);
    var dialogObj = new CKEDITOR.dialog(editor, 'smiley');




我收到以下错误:未捕获的TypeError:无法读取属性' dir'未定义的     在CKEDITOR.dialog(ckeditor.js:573)     在testCKE.html:24

我使用完整版本4。6。2(2017年1月12日)

dir似乎是editor.lang的一个元素 我尝试设置config.language和config.defaultLanguage

我尝试使用和不使用jquery,没有区别

编辑器打开正常并且似乎有效。 我做错了什么?

更新:找到答案,见下文。如果有更好的方法仍然感兴趣。

1 个答案:

答案 0 :(得分:0)

我使用基于samples / old / dialog文件的代码生成了对话框,缩减版本:

var field = {id: "html1"};
CKEDITOR.on( 'instanceCreated', function( ev ){
    var editor = ev.editor;

    // Listen for the "pluginsLoaded" event, so we are sure that the
    // "dialog" plugin has been loaded and we are able to do our
    // customizations.
    editor.on( 'pluginsLoaded', function() {

        // If our custom dialog has not been registered, do that now.
        if ( !CKEDITOR.dialog.exists( 'myDialog' ) ) {

            CKEDITOR.dialog.add( 'myDialog', function(){
                return  {title: 'My Dialog',
                    minWidth: 400,
                    minHeight: 200,
                    contents:[
                        {
                            id: 'tabA',
                            label: 'TabA',
                            title: 'TabA',
                            elements: [
                                {
                                    id: 'button1',
                                    type: 'button',
                                    label: 'Button Field'
                                }
                            ]
                        }
                    ]
                };
            } );
        }

        // Register the command used to open the dialog.
        editor.addCommand( 'myDialogCmd', new CKEDITOR.dialogCommand( 'myDialog' ) );

        // Add the a custom toolbar buttons, which fires the above
        // command..
        editor.ui.add( 'MyButton', CKEDITOR.UI_BUTTON, {
            label: 'My Dialog',
            command: 'myDialogCmd'
        });
    });
});

var editor = CKEDITOR.replace(field.id);