TinyMCE Create sub-menu in context menu

核能气质少年 提交于 2019-12-08 11:31:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!