好的,在这种情况下,您需要加载上下文菜单插件(在加载自定义插件之前执行此操作!)
plugins: '...,contextmenu,....,customcontextmenu,...',
这是一个自己的上下文菜单插件的完整示例代码。您需要在插件目录的名为“contextmenu”的子目录中的名为“editor_plugin.js”的文件(和名为“editor_plugin_src.js”的文件)中包含此代码。
(function() {
tinymce.PluginManager.requireLangPack('customcontextmenu');
tinymce.create('tinymce.plugins.customcontextmenu', {
init : function(ed, url) {
ed.addCommand('custom_option', function() {
// do what you want here!!!
});
// we need the real contextmenu in order to make this work
if (ed && ed.plugins.contextmenu) {
// contextmenu gets called - this is what we do
ed.plugins.contextmenu.onContextMenu.add(function(th, m, e, col) {
// remove all options from standard contextmenu
m.removeAll();
// only if selected node is an image do this
if (typeof e !== "undefined" && e.nodeName.toLowerCase() == 'img'){
th._menu.add({
title: 'Option 1',
icon: 'option1', // you might need to specify an image here
cmd: 'custom_option' // call command custom_option
});
m.addSeparator();
// Second option
//m.add({
// title: 'Option 2',
// icon: 'option2',
// cmd: 'custom_option2'
//});
}
else {
// you might want to hinder the display of the contextmenu in all other cases
// or present other options....
}
});
}
});
},
// Register plugin
tinymce.PluginManager.add('customcontextmenu', tinymce.plugins.customcontextmenu);
})();
确保括号设置正确(我不得不复制/粘贴和删除部分代码,因此可能缺少括号)。