CKEditor openDialog placeholders

CKEditor openDialog placeholders

本文关键字:placeholders openDialog CKEditor      更新时间:2023-09-26

我有一个函数,当按下某个键时打开占位符对话框。但是,当我选择一个占位符并单击"Ok"时,占位符值不会插入编辑器中。但是当我通过工具栏按钮打开占位符对话框时,占位符确实被插入到编辑器中。

谁能告诉我我做错了什么?

我在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在firebug控制台上是可见的,但是当我通过按键打开对话框时,它是不可见的。

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

在我的placeholder/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');

这是可行的!