【问题标题】:TinyMCE - put plugins in a dropdown? (Custom Toolbar Menu Button)TinyMCE - 将插件放在下拉列表中? (自定义工具栏菜单按钮)
【发布时间】:2016-11-05 23:25:44
【问题描述】:

我在 TinyMCE 4 中有 4 个用于处理图像的不同插件,以及许多其他插件。我想让事情变得更整洁/干净。

是一种将现有插件添加到 TinyMCE 4 中的下拉菜单的方法吗?

我知道这种为新内容创建下拉菜单的方法: https://www.tinymce.com/docs/demo/custom-toolbar-menu-button/

在初始化中:

setup: function(editor) {
    editor.addButton('mybutton', {
      type: 'menubutton',
      text: 'My button',
      icon: false,
      menu: [{
        text: 'Menu item 1',
        onclick: function() {
          editor.insertContent('&nbsp;<strong>Menu item 1 here!</strong>&nbsp;');
        }
      }, {
        text: 'Menu item 2',
        onclick: function() {
          editor.insertContent('&nbsp;<em>Menu item 2 here!</em>&nbsp;');
        }
      }]
    });
  },

但是我不明白如何在其中添加插件。像插件“图像”或“链接”。

有人知道吗?

【问题讨论】:

    标签: javascript tinymce tinymce-4 tinymce-plugins


    【解决方案1】:

    每个插件都有自己的 JS 文件,您将在每个插件中看到代码,了解它如何提供其功能。它可能会添加工具栏按钮、完整菜单、现有菜单中的菜单项等。如果您想更改菜单/工具栏中的内容,则需要在每个插件中修改该代码。例如,您会在 link 插件的代码中找到它:

    editor.addButton('link', {
        icon: 'link',
        tooltip: 'Insert/edit link',
        shortcut: 'Meta+K',
        onclick: createLinkList(showDialog),
        stateSelector: 'a[href]'
    });
    
    editor.addButton('unlink', {
        icon: 'unlink',
        tooltip: 'Remove link',
        cmd: 'unlink',
        stateSelector: 'a[href]'
    });
    
    editor.addShortcut('Meta+K', '', createLinkList(showDialog));
    editor.addCommand('mceLink', createLinkList(showDialog));
    
    this.showDialog = showDialog;
    
    editor.addMenuItem('link', {
        icon: 'link',
        text: 'Insert/edit link',
        shortcut: 'Meta+K',
        onclick: createLinkList(showDialog),
        stateSelector: 'a[href]',
        context: 'insert',
        prependToContext: true
    });
    

    如果您想更改添加的按钮/菜单或它们出现的位置,您需要修改每个插件文件中的相关代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-23
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 2012-07-17
      • 2012-05-26
      • 1970-01-01
      • 2016-10-21
      相关资源
      最近更新 更多