CK Editor自定义插件创建一个按钮

时间:2015-12-04 03:06:19

标签: drupal ckeditor

我一直在尝试创建一个自定义插件来为工具栏创建一个“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中。 知道为什么这不起作用吗?

1 个答案:

答案 0 :(得分:0)

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