2017-05-11 74 views
0

我有以下的測試腳本:CKEditor的錯誤創建對話框

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

我得到以下錯誤:未捕獲的類型錯誤:在CKEDITOR.dialog(不能讀取的不確定 財產「目錄」 ckeditor.js:573) 在testCKE.html:24

我使用的是完整版本4.6.2(2017年1月12日)

目錄似乎是和editor.lang 的元素我設置config.language嘗試config.defaultLanguage

我有和沒有jQuery的試了一下,沒有差別

編輯器打開罰款,似乎工作。 我在做什麼錯?

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

回答

0

我的對話框使用基於樣本代碼工作/老/對話框的文件,縮減版本,:

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);