CKEditor自定义插件创建按钮

CK Editor custom plugin to create a button

我一直在尝试创建一个自定义插件来为工具栏创建一个 'h1' 按钮。这是我的插件代码 -

"use strict";

var pluginName = 'customButtons';

CKEDITOR.plugins.add( 'customButtons', {
    icons: 'h1_btn', // If you wish to have an icon...

    init: function( editor ) {
        // Tagname which you'd like to apply.
        var tag = 'h1';
            // Note: that we're reusing.
            //style = new CKEDITOR.style( editor.config[ 'format_' + tag ] );
        var style = new CKEDITOR.style( { element: 'h1' } );

        // Creates a command for our plugin, here command will apply style. All the logic is
        // inside CKEDITOR.styleCommand#exec function so we don't need to implement anything.
        editor.addCommand( pluginName, new CKEDITOR.styleCommand( style ) );

        // This part will provide toolbar button highlighting in editor.
        editor.attachStyleStateChange( style, function( state ) {
            !editor.readOnly && editor.getCommand( pluginName ).setState( state );
        } );

        // This will add button to the toolbar.
        editor.ui.addButton( 'h1', {
            label: 'Click to apply format',
            command: 'customButtons',
            toolbar: 'insert'
        } );
    }
} );

我也将插件添加到 config.js。 知道为什么这不起作用吗?

没关系。我想出了答案。但是让问题成为现实,以防有人遇到同样的问题。 原来 ckeditor.editor.php 有一个错误(插件的目录名称错误)。我将其改回文件夹结构中的目录名称,瞧,它起作用了!!