是否可以在ckeditor插件中设置子菜单?即
答案 0 :(得分:4)
是。支持子菜单(菜单组)。有example如何定义它们。如果您在编辑器中加载了tabletools
插件,则可以在右键单击某个表格单元格时观察它。
答案 1 :(得分:1)
此代码段必须添加父菜单项并从服务器获取子菜单项,并在父菜单下添加这些项。
var myMenu{
openEditor: function(sender) {
sender.ckeditor(function(element) {
}, {
on: {
instanceReady: function(c) {
myMenu.setupParameterMenu(c.editor);
}
}
});
},
setupParameterMenu: function(ceditor) {
ceditor.addMenuGroup('Parameters');
var subItems = {};
var parentMenu = {};
parentMenu.label = "Dynamic Parameters";
parentMenu.group = 'Parameters';
parentMenu.order = 1;
parentMenu.getItems = function() {
return subItems;
};
ceditor.addMenuItem("Dynamic Parameters", parentMenu);
ceditor.contextMenu.addListener(function(element, selection) {
return {"Dynamic Parameters": CKEDITOR.TRISTATE_OFF};
});
$.getJSON("/JSON/Parameters", function(json) {
for (var i = 0; i < json.length; i++) {
var subMenu = myMenu.subMenuItem(json[i], ceditor);
for (var key in subMenu) {
subItems[key] = subMenu[key];
}
}
});
},
subMenuItem: function(param, ceditor) {
ceditor.addCommand(param, {
exec: function(editor)
{
var element = CKEDITOR.dom.element.createFromHtml('<span contenteditable="false">' + param + '</span>');
editor.insertElement(element);
}
});
var zet = {};
zet.label = param;
zet.command = param;
zet.group = 'Parameters';
zet.order = i + 1;
ceditor.addMenuItem("" + param, zet);
var n = {};
n[param] = CKEDITOR.TRISTATE_OFF;
return n;
}
}