[英]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.