我也遇到了这个问题。感谢CKEditor的糟糕文档,我尝试了整个下午的不同方式终于成功了。
该代码在我的网站 Drupal 6 和 CKEditor 4 上运行良好。
// Assume I already Have 3 commands
// insertTick, insertTickxxx, and insertTickxxxandxxx
if (editor.addMenuItems) {
// 1st, add a Menu Group
// tip: name it the same as your plugin. (I'm not sure about this)
editor.addMenuGroup('tick', 3);
// 2nd, use addMenuItems to add items
editor.addMenuItems({
// 2.1 add the group again, and give it getItems, return all the child items
tick :
{
label : 'Insert Tick',
group : 'tick',
order : 21,
getItems : function() {
return {
tick_insertTick : CKEDITOR.TRISTATE_OFF,
tick_insertQuestionMark : CKEDITOR.TRISTATE_OFF,
tick_insertTickandQuestion : CKEDITOR.TRISTATE_OFF
};
}
},
// 2.2 Now add the child items to the group.
tick_insertTick :
{
label : 'Insert a tick',
group : 'tick',
command : 'insertTick',
order : 22
},
tick_insertQuestionMark :
{
label : 'Insert Question Mark',
group : 'tick',
command : 'insertQuestionMark',
order : 23
},
tick_insertTickandQuestion :
{
label : 'insert Tick and Question',
group : 'tick',
command : 'insertTickandQuestion',
order : 24
}
});
}
// 3rd, add Listener, and return the Menu Group
if (editor.contextMenu) {
editor.contextMenu.addListener(function(element, selection) {
return {
tick : CKEDITOR.TRISTATE_OFF
};
});
}
这将显示为
插入勾号 -> 插入勾号
-------------- 插入问号
-------------- 插入勾号和问号