0

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

VishnuPrasad
  • 1,078
  • 5
  • 17
  • 36

1 Answers1

0

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
RRR
  • 1,074
  • 8
  • 11
  • I have tried so, but here in contextmenu only one element is passed, i need to mention fig and insert menus seperatly. ie, contextmenu: "insert_element,insert_fig", – VishnuPrasad Apr 26 '16 at 07:12
  • you can pass as many elements as possible. just check updated fiddle https://jsfiddle.net/9ue2pLLz/3/ – RRR Apr 26 '16 at 07:15
  • so, how can i specify "insert text" wont be there in "insert" menu – VishnuPrasad Apr 26 '16 at 07:23
  • just remove `{ text:'Insert Text', onclick:function(){ alert('clicked Insert Text'); } },` – RRR Apr 26 '16 at 07:26
  • if you can show me the image or something which will illustrate the final output i will update the fiddle accordingly – RRR Apr 26 '16 at 07:27
  • i am creating context menus as a plugin. What i need is dynamically show each menu/sub-menu by passing on tinymce.init via contextmenu. I have clearly mentioned that in question – VishnuPrasad Apr 26 '16 at 07:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/110221/discussion-between-rb-vishnu-and-rrr). – VishnuPrasad Apr 26 '16 at 07:37