问题
I have created two context menus in TinyMCE
editor.addMenuItem('insert_element', {
text: 'Insert',
onclick: insert_action,
});
editor.addMenuItem('insert_fig', {
text: 'Figure',
onclick: insert_figure,
context: 'insert_element',
prependToContext: true
});
and passed the context menus in tinymce.init
...
tinymce.init({
...
contextmenu: "insert_element,insert_fig",
...
});
...
Now on right clicking in active text area, i got two menus as "Insert" and "Figure".
I would like to change the "Figure" menu as a sub-menu of insert. How it would be possible by passing contextmenu via tinymce.init. I just used context option to make submenu but it's not working
回答1:
Hi kindly check https://jsfiddle.net/9ue2pLLz/2/ ...
jQuery
$(document).ready(function(){
tinymce.init({
selector: "textarea",
plugins: "contextmenu preview code",
contextmenu: "insert_element" ,
setup: function(editor) {
editor.addMenuItem('insert_element', {
text:'Insert',
menu:[
{
text:'Insert Figure',
onclick:function(){
alert('clicked Insert Figure');
}
},
{
text:'Insert Text',
onclick:function(){
alert('clicked Insert Text');
}
},
]
}) //editor.addMenuItem
} // Setup FUnction
}); // TinyMCE init
}); // Document ready
来源:https://stackoverflow.com/questions/36855835/tinymce-create-sub-menu-in-context-menu