【问题标题】:TinyMCE Create sub-menu in context menuTinyMCE 在上下文菜单中创建子菜单
【发布时间】:2016-08-19 17:52:46
【问题描述】:

我在 TinyMCE 中创建了两个上下文菜单

editor.addMenuItem('insert_element', {
    text: 'Insert',
    onclick: insert_action,
});

editor.addMenuItem('insert_fig', {
    text: 'Figure',
    onclick: insert_figure,
    context: 'insert_element',
    prependToContext: true
});

并在 tinymce.init 中传递上下文菜单

...
tinymce.init({
...
contextmenu: "insert_element,insert_fig",
...
});
...

现在右键单击活动文本区域,我有两个菜单“插入”和“图”。

我想将“图形”菜单更改为插入的子菜单。 通过 tinymce.init 传递 contextmenu 是如何实现的。 我只是使用上下文选项来制作子菜单,但它不起作用

【问题讨论】:

    标签: javascript jquery tinymce contextmenu menuitem


    【解决方案1】:

    您好,请检查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
    

    【讨论】:

    • 我已经尝试过了,但是这里在 contextmenu 中只传递了一个元素,我需要单独提及 fig 并插入菜单。即,上下文菜单:“insert_element,insert_fig”,
    • 你可以传递尽可能多的元素。只需检查更新的小提琴jsfiddle.net/9ue2pLLz/3
    • 那么,如何指定“插入文本”不会出现在“插入”菜单中
    • 删除{ text:'Insert Text', onclick:function(){ alert('clicked Insert Text'); } },
    • 如果你可以给我看图片或其他可以说明最终输出的东西,我会相应地更新小提琴
    猜你喜欢
    • 2014-07-27
    • 1970-01-01
    • 2018-11-23
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 2016-06-29
    相关资源
    最近更新 更多