繁体   English   中英

如何在ckeditor中使用多个插件?

[英]How do I use multiple plugin's in ckeditor?

我需要将h1,h2,h3标签添加到ckeditor的键绑定中,我发现此简单功能可以实现此目的。
该功能可以正常工作,并且符合预期,但是我只能使用一次,如果我将同一功能复制到另一个目录并尝试包含它,则无法使用。 我究竟做错了什么?

位置: plugins / button-h1 / plugin.js

 var a= {
    exec:function(editor){
    var format = {
    element : "h1"
    };
    var style = new CKEDITOR.style(format);
        style.apply(editor.document);
    }
},

// Add the plugin
b="button-h1";
CKEDITOR.plugins.add(b,{
    init:function(editor){
    editor.addCommand(b,a);
    editor.ui.addButton("button-h1",{
    label:"Button H1",
    icon: this.path + "button-h1.png",
    command:b
    });
}
});

但是,当我在另一个名为“ button-h2”的文件夹中创建另一个插件时,使用相同的代码但使用不同的名称和标记,则无法正常工作。

位置: plugins / button-h2 / plugin.js

// Exactly the same as above, but with "h2" tags.
var a= {
    exec:function(editor){
    var format = {
    element : "h2"
    };
    var style = new CKEDITOR.style(format);
        style.apply(editor.document);
    }
},

// Add the plugin
b="button-h2";
CKEDITOR.plugins.add(b,{
    init:function(editor){
    editor.addCommand(b,a);
    editor.ui.addButton("button-h2",{
    label:"Button H2",
    icon: this.path + "button-h2.png",
    command:b
    });
}
});

基本上,我需要一个用户能够使用“ CTRL + 1”在所选文本周围添加标题标签。
此方法有效,除了我只能将其仅用于一个标题,即H1或H2,不能同时用于两个或多个。

在我的config.js中,我可以进行以下设置。

config.extraPlugins = "button-h1,button-h2";
config.keystrokes =
[
    [ CKEDITOR.CTRL + 49 /*1*/, 'button-h1' ],
    [ CKEDITOR.CTRL + 50 /*2*/, 'button-h2' ]

];

所以,
-该插件有效,但是我只能在H1或H2上使用,为什么不能同时使用?
我是否需要将其放在函数或其他内容中,以便可以同时执行一次以上?

我找到了答案。 我需要将其包装在一个匿名函数中。

(function(){
var a= 
{
    exec:function(editor){
        var format = {
        element : "h1"
        };
    var style = new CKEDITOR.style(format);
    style.apply(editor.document);
    }
},

b="tags-h1";
CKEDITOR.plugins.add(b,{
    init:function(editor){
    editor.addCommand(b,a);
    editor.ui.addButton(b,{
    label:"Heading 1",
    icon: this.path + "heading-1.png",
    command:b
    });
    }
});
})();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM