整合tinymce工具栏按钮

整合效果

整合菜单栏,大致分为以下几种:

1.拆分工具栏

效果

在这里插入图片描述

实现方式

// 拆分工具栏代码
editor.ui.registry.addSplitButton('myButton', {
      text: 'My Button',
      icon: 'info',
      tooltip: 'This is an example split-button',
      onAction: () => editor.insertContent('<p>You clicked the main button</p>'),
      onItemAction: (api, value) => editor.insertContent(value),
      fetch: (callback) => {
        const items = [
          {
            type: 'choiceitem',
            icon: 'notice',
            text: 'Menu item 1',
            value: '&nbsp;<em>You clicked menu item 1!</em>'
          },
          {
            type: 'choiceitem',
            icon: 'warning',
            text: 'Menu item 2',
            value: '&nbsp;<em>You clicked menu item 2!</em>'
          }
        ];
        callback(items);
      }
    });

2.工具栏组

效果

在这里插入图片描述

实现方式

// An highlighted block
editor.ui.registry.addGroupToolbarButton('geshi', {
      icon: 'createBottom',
      tooltip: 'geshi',
      items: 'underline strikethrough subscript superscript backcolor forecolor',
      onSetup: stateToggleG1(editor)
 });

3. 菜单工具栏按钮

效果

在这里插入图片描述

在这里插入图片描述

实现方式

editor.ui.registry.addMenuButton('action', {
      //动作按钮组
      icon: 'g-action',
      tooltip: 'action',
      fetch: function (callback) {
        const items = [
          {
            type: 'menuitem',
            text: 'Rename',
            icon: 'edit-block',
            onAction: function () {
              alert('暂未开发')
            },
          },
          {
            type: 'menuitem',
            text: 'Branch',
            icon: 'branch',
            onAction: function () {
              alert('暂未开发')
            },
          },
        ];
        callback(items);
      },
    });

Tips

以上代码均为tinymce官方api,可以在引用tinymce的组件时的init变量中的setup函数中写入,也可以写在扩展文件plugin.js,通过插件引入,具体可以参考我另一篇引入自定义插件的文章。

最近准备整合一下所有的功能,我的个人github上面其实有开源的这部分功能,暂时还是私有未公开,后面我抽时间优化后会公开,感兴趣的可以持续关注下。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值