2015-10-14 40 views
0

我有一個函數,當某個鍵被按下時打開佔位符對話框。但是,當我選擇佔位符並單擊「確定」時,佔位符值不會插入到編輯器中。但是當我通過工具欄按鈕打開佔位符對話框時,佔位符會插入到編輯器中。CKEditor openDialog佔位符

有人能告訴我我做錯了什麼嗎?

我在plugin.js補充說:

editor.on('key', function(e) { 
 
    if (e.data.domEvent.$.key == "[") { 
 
    editor.openDialog('placeholder'); 
 
    }; 
 
});

我在placeholder.js改變了一些事情:
可用的佔位符有一個下拉列表中。
佔位符數據已由init傳遞。

正如您所看到的,我在commit: function(widget){中放置了console.log(this.getValue());。 當我通過工具欄中的佔位符按鈕打開對話框時,在螢火蟲控制檯中可以看到console.log,但是當我通過按鍵打開對話框時,它不可見。

'use strict'; 
 

 
CKEDITOR.dialog.add('placeholder', function(editor) { 
 
    var lang = editor.lang.placeholder, 
 
     generalLabel = editor.lang.common.generalTab, 
 
     validNameRegex = /^[^\[\]<>]+$/; 
 
    return { 
 
    title: lang.title, 
 
    minWidth: 300, 
 
    minHeight: 80, 
 
    contents: [ 
 
     { 
 
     id: 'info', 
 
     label: generalLabel, 
 
     title: generalLabel, 
 
     elements: [ 
 
      // Dialog window UI elements. 
 
      { 
 
      id: 'name', 
 
      type: 'select', 
 
      items: editor.config.placeholders, 
 
      style: 'width: 100%;', 
 
      label: lang.name, 
 
      'default': '', 
 
      required: true, 
 
      validate: CKEDITOR.dialog.validate.regex(validNameRegex, lang.invalidName), 
 
      setup: function(widget) { 
 
       this.setValue(widget.data.name); 
 
      }, 
 
      commit: function(widget) { 
 
       console.log(this.getValue()); 
 
       widget.setData('name', this.getValue()); 
 
      } 
 
      } 
 
     ] 
 
     } 
 
    ] 
 
    }; 
 
});

回答

0

而不是使用我的佔位符/ plugin.js內以下代碼:

editor.on('key', function(e) { 
 
    console.log(e.data.domEvent.$); 
 
    if (e.data.domEvent.$.key == "[") { 
 
    editor.openDialog('placeholder'); 
 
    }; 
 
});

我啓動編輯器時使用的setKeystroke功能:

var editor = CKEDITOR.replace('editor',{ 
 
    placeholders: ["test1", "test2"], 
 
    extraPlugins: 'placeholder' 
 
}); 
 
editor.setKeystroke(219, 'placeholder');

而這個作品!