Javascript 如何从tinymce中的右键单击菜单中删除指定的选项?
我想从tinymce中的右键单击菜单中删除图像属性选项。我正在使用tinymce 3.x版本,请帮助我。您可以执行以下操作:Javascript 如何从tinymce中的右键单击菜单中删除指定的选项?,javascript,jquery,tinymce,Javascript,Jquery,Tinymce,我想从tinymce中的右键单击菜单中删除图像属性选项。我正在使用tinymce 3.x版本,请帮助我。您可以执行以下操作: tinyMCE.init({ setup: function (ed) { ed.onInit.add(editor_oninit); } ... }); function editor_oninit(ed) { // Add hook for onContextMenu so that Insert Image can be r
tinyMCE.init({
setup: function (ed) {
ed.onInit.add(editor_oninit);
}
...
});
function editor_oninit(ed) {
// Add hook for onContextMenu so that Insert Image can be removed
ed.plugins.contextmenu.onContextMenu.add(editor_remove_image);
}
以及功能
function editor_remove_image(sender, menu) {
// create a new object
var otherItems = {};
for (var itemName in menu.items) {
var item = menu.items[itemName];
if (/^mce_/.test(itemName)) {
if (item.settings) {
if (item.settings.cmd == "mceImage" || item.settings.cmd == "mceAdvImage") {
// skip these items
continue;
}
}
}
// add all other items to this new object, so it is effectively a clone
// of menu.items but without the offending entries
otherItems[itemName] = item;
}
// replace menu.items with our new object
menu.items = otherItems;
}
我第一次使用这个TinyMCE,实际上是在寻找解决这里所问问题的方法 这是我的TinyMCE脚本:
tinymce.init({
selector: "textarea#elm1",
images_upload_credentials: false,
theme: "modern",
branding: false,
<!-- elementpath: false, -->
menubar:false,
<!-- preview_styles: false, -->
height:300,
automatic_uploads: false,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
]
});
对于使用TinyMCE 5的用户,一个解决方案可能是明确指定以下内容中允许的项目:
删除表的过程是否相同?
plugins: [
"advlist autolink link lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
]
tinymce.init({
...
contextmenu: 'link table' /*just do not mention the 'image'*/
...
});