[英]How do I use multiple plugin's in ckeditor?
I needed to add the h1, h2, h3 tags to key bindings for ckeditor and I found this simple function to do this. 我需要将h1,h2,h3标签添加到ckeditor的键绑定中,我发现此简单功能可以实现此目的。
This function works fine and as expected, But I can only use it once, If I copy the same function to another directory and try to include it, it doesnt work. 该功能可以正常工作,并且符合预期,但是我只能使用一次,如果我将同一功能复制到另一个目录并尝试包含它,则无法使用。 What am i doing wrong? 我究竟做错了什么?
Location: plugins/button-h1/plugin.js 位置: 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
});
}
});
But When I create another plugin inside another folder named 'button-h2', With the same code but different names and tags, It doesnt work. 但是,当我在另一个名为“ button-h2”的文件夹中创建另一个插件时,使用相同的代码但使用不同的名称和标记,则无法正常工作。
Location: plugins/button-h2/plugin.js 位置: 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
});
}
});
Basically, I need a user to be able to use "CTRL + 1" to add heading tags around selected text. 基本上,我需要一个用户能够使用“ CTRL + 1”在所选文本周围添加标题标签。
This method works, except I can only use it for one of the headings only, either H1 or H2, not both or more. 此方法有效,除了我只能将其仅用于一个标题,即H1或H2,不能同时用于两个或多个。
In my config.js, I have the following to set everything up. 在我的config.js中,我可以进行以下设置。
config.extraPlugins = "button-h1,button-h2";
config.keystrokes =
[
[ CKEDITOR.CTRL + 49 /*1*/, 'button-h1' ],
[ CKEDITOR.CTRL + 50 /*2*/, 'button-h2' ]
];
So, 所以,
- The Plugin Works, but I can only use it on H1 or H2, NOT BOTH, WHY? -该插件有效,但是我只能在H1或H2上使用,为什么不能同时使用?
Do I need to put this within a function or something so it can be executed more then once at the same time? 我是否需要将其放在函数或其他内容中,以便可以同时执行一次以上?
I found the answer for this. 我找到了答案。 I needed to wrap this in a anonymous function. 我需要将其包装在一个匿名函数中。
(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.