【问题标题】:Ckeditor 3 - Insert element on click when toolbar button is selectedCkeditor 3 - 选择工具栏按钮时单击插入元素
【发布时间】:2018-08-22 18:25:32
【问题描述】:

我想在点击 Ckeditor textarea 窗口时插入某些文本或 html(默认和重复)。

我创建了一个自定义插件,它可以在单击工具栏按钮时添加一些文本,或者在通过 sn-p 下方单击 textarea 窗口时添加文本。

        CKEDITOR.plugins.add( 'duppointer',
        {
            init: function( editor )
            {

                editor.addCommand( 'insertDup',
                {
                    modes : { wysiwyg:1, source:1 },
                    exec : function( editor )
                    {    
                        editor.insertText( '#' );
                    }
                });

                editor.on( 'contentDom', function(){
                    this.document.on( 'click', function() {
                        editor.insertText( '#' );
                    });
                });

                editor.ui.addButton( 'duppointer',
                {
                    label: 'Insert Duplicate Text',
                    command: 'insertDup',
                } );
            }
        } );

但是,我只想在工具栏按钮处于活动状态时在单击时插入文本,否则指针单击必须正常。

有可能实现吗?

【问题讨论】:

    标签: ckeditor


    【解决方案1】:

    由于没有人回复,我开始翻遍API,了解按钮的状态。最后,我得到了我正在寻找的东西,如果它是正确的方法,但它对我有用,

    CKEDITOR.plugins.add( 'duppointer',
    {
        init: function( editor )
        {
    
            var ccommand = editor.addCommand( 'duppointer',
            {
                modes : { wysiwyg:1, source:1 },
                exec : function( editor )
                {    
                    ccommand.toggleState();
                },
                editorfocus: true,
            });
    
            editor.on( 'contentDom', function(){
                this.document.on( 'click', function() {
                    if(ccommand.state == CKEDITOR.TRISTATE_ON){
                        editor.insertText( '#' );
                    }
                });
              });
    
            editor.ui.addButton( 'duppointer',
            {
                label: 'Insert Duplicate',
                command: 'duppointer',
                icon: this.path + 'images/dup.jpg'
            } );
        }
    } );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多