【问题标题】:TinyMCE v4 adding custom items to the contextmenuTinyMCE v4 将自定义项目添加到上下文菜单
【发布时间】:2014-03-14 00:02:45
【问题描述】:

我正在我的一个网站上升级 TinyMCE,并尝试将自定义项添加到上下文菜单插件。我似乎无法找到它的任何文档,因为我只能找到 v3。

在上一个版本中,我可以轻松地将自定义链接添加到上下文菜单,但由于 TinyMCE 发生了很大变化,我很难添加新链接。谁能指出我正确的文档?

我以前在上一个版本中使用过以下内容:

ed.addCommand('fileMan', function(e) {
    fileman();
    hide(ed, e);
});

m.add({title : 'Filemanager', icon : 'image', cmd : 'fileMan'});

【问题讨论】:

    标签: javascript jquery contextmenu tinymce-4


    【解决方案1】:

    我能够弄清楚这一点。这是我所做的:

    • 在插件目录中创建了一个名为 fileman 的新文件夹
    • 创建了一个名为 plugin.js 的文件,并将本文末尾的代码添加到其中
    • 缩小代码并将缩小后的代码放入plugin.min.js
    • 编辑了contextmenu插件文件夹中的plugin.min.js并将fileman添加到加载的插件列表中
    • 在初始化编辑器时将fileman添加到加载的插件列表中

    代码:

    tinymce.PluginManager.add('fileman', function(editor) {
        editor.addMenuItem('fileman', {
            icon: 'image',
            text: 'Filemanager',
            shortcut: 'Ctrl+J',
            onclick: function() {
                fileman.launch('editor');
            },
            context: 'insert',
            prependToContext: true
        });
    });
    

    【讨论】:

    • 我认为上述解决方案不是添加上下文菜单,而是添加不同的新菜单。
    【解决方案2】:

    这是一个有点棘手但完美的解决方案,在尝试了很多事情后对我有用。

    editor.on('contextmenu', function(editor) {
    
    this.settings.contextmenu = 'fileman | link openlink image inserttable | cell row column deletetable';
    
    var exampleMenuItem = this.menuItems['italic'];
    this.menuItems['fileman'] = exampleMenuItem;
    
    this.menuItems['fileman'].cmd = 'mceFileMan';
    this.menuItems['fileman'].icon = '../../file-icon.png';
    this.menuItems['fileman'].text = 'File Manager';
    

    });

    【讨论】:

      猜你喜欢
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多