AngularCKEditor5在按钮点击时添加自定义类
创始人
2024-10-23 16:01:12
0
  1. 在您的 Angular 项目中安装 CKEditor 5 和自定义插件。您可以使用以下命令进行安装:
npm install --save @ckeditor/ckeditor5-build-classic
npm install --save @ckeditor/ckeditor5-angular
npm install --save ckeditor5-custom-class
  1. 在您的组件中导入和定义您的 CKEditor 编辑器:
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import { CustomClassPlugin } from 'ckeditor5-custom-class';

@Component({
  selector: 'app-editor',
  template: ''
})
export class EditorComponent {
  public Editor = ClassicEditor;
  public config = {
    plugins: [ CustomClassPlugin ],
    toolbar: [ 'customClass' ]
  };

  // ... your event handlers
}
  1. 在您的编辑器工具栏中添加自定义类的按钮。您可以使用 customClass 工具栏按钮来启用自定义类插件:
public config = {
  plugins: [ CustomClassPlugin ],
  toolbar: [ 'customClass' ]
};
  1. 在点击自定义类按钮时动态给选中内容添加自定义类。您可以在 CustomClassPlugin 中添加代码以在按钮点击时应用自定义类:
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';

export class CustomClassEditing extends Plugin {
  static get requires() {
    return [ CustomClassUI ];
  }

  init() {
    const editor = this.editor;

    editor.editing.view.document.on( 'click', ( evt, data ) => {
      const target = evt.target;

      if ( target.is( 'element' ) ) {
        const ui = editor.plugins.get( CustomClassUI );
        ui.selectClass( target );
      }
    } );
  }
}

export class CustomClassUI extends Plugin {
  static get pluginName() {
    return 'CustomClassUI';
  }

  init() {
    const editor = this.editor;

    editor.ui.componentFactory.add( 'customClass', locale => {

相关内容

热门资讯

无独有偶!德普之星透视,微信微... 无独有偶!德普之星透视,微信微乐陕西小程序破解器,揭露脚本(有挂规律)-哔哩哔哩1、完成德普之星透视...
透视了解!wepokerplu... 透视了解!wepokerplus开挂,wepoker辅助器有哪些功能(透视)切实是有app(哔哩哔哩...
反观!大菠萝免费辅助,微乐小程... 反观!大菠萝免费辅助,微乐小程序自建房辅助下载,专业透视(有挂细节)-哔哩哔哩1、不需要AI权限,帮...
透视普及!德普之星私人局透视,... 透视普及!德普之星私人局透视,德扑圈有透视吗(透视)确实有app(哔哩哔哩)一、游戏安装教程牌型概率...
昨日!哈糖大菠萝挂,微信小程序... 昨日!哈糖大菠萝挂,微信小程序微乐辅助器免费下载,透视脚本(有挂技巧)-哔哩哔哩在进入哈糖大菠萝挂软...
脚本分享!德扑HHpoker有... 脚本分享!德扑HHpoker有挂吗,德州局怎么透视(透视)本来真的是有器(哔哩哔哩)1、每一步都需要...
透视脚本!hardrock透视... 透视脚本!hardrock透视工具,微信微乐辅助ios,专业脚本(有挂秘诀)-哔哩哔哩;1、玩家可以...
脚本普及!德普软件,德普之星辅... 脚本普及!德普软件,德普之星辅助工具如何设置(透视)果然是真的挂(哔哩哔哩)亲,关键说明,透视脚本安...
透视好牌!wepoker作必弊... 透视好牌!wepoker作必弊视频,微信微乐游戏苹果辅助器,教你脚本(证实有挂)-哔哩哔哩1、点击下...
透视解谜!德普之星辅助工具如何... 透视解谜!德普之星辅助工具如何设置,德普之星透视(透视)其实真的有插件(哔哩哔哩)该软件可以轻松地帮...