将 ckeditor 小部件添加到自定义工具栏

Add ckeditor widget to a custom toolbar

我正在尝试添加 placeholder widget to my custom toolbar- 我的生活我想不通:

<script src="https://cdn.ckeditor.com/4.5.2/standard-all/ckeditor.js"></script>

它适用于默认工具栏:

<textarea cols="80" id="editor1" name="editor1" rows="10">test1</textarea>

CKEDITOR.replace( 'editor1', {
  extraPlugins: 'placeholder',
  height: 50
} );

但没有自定义工具栏:

<textarea cols="80" id="editor2" name="editor2" rows="10">test2</textarea>

CKEDITOR.replace( 'editor2', {
  extraPlugins: 'placeholder',
  height: 50,
  toolbar: [{ name: 'tools',group: 'tools', items: [ 'Bold','Placeholder', 'Redo' ], groups: [ 'tools'] }]
} );

据我了解,有两种方法可以将按钮插入工具栏: 1. 在工具栏本身中使用名称(编辑器 2 示例) 2. 使用 editor.ui.addButton 函数:

editor.ui.addButton && editor.ui.addButton( 'CreatePlaceholder', {
                label: lang.toolbar,
                command: 'placeholder',
            //  toolbar: 'insert,5',
                toolbar: 'clipboard,0',
                icon: 'placeholder'
            } );

我创建了一个 fiddle 来显示:

  1. 带占位符按钮的默认工具栏
  2. 我无法将占位符按钮添加到的自定义工具栏

请问 show/tell 如何将占位符添加到自定义工具栏?谢谢

您已将按钮命名为 'CreatePlaceholder',因此您应该在工具栏中使用此名称。

editor.ui.addButton && editor.ui.addButton( 'CreatePlaceholder', ...

CKEDITOR.replace( 'editor3', {
    ...
    toolbar: [{ name: 'tools',group: 'tools', items: [ 'Bold','CreatePlaceholder', ...

完整代码: http://jsfiddle.net/nw3o4gy5/

也看看CKEDITOR.ui.addButton