【问题标题】:CKEditor 4 + Enhanced Image, center by default. FYICKEditor 4 + 增强图像,默认居中。供参考
【发布时间】:2018-08-31 16:14:00
【问题描述】:

这不是一个问题,而是一个解决方案(带有一个肮脏的小把戏)。

我需要在 CKEditor 中默认插入一个“居中”对齐的图像。我找不到工作示例,所以我花了很多时间想出了以下答案。

【问题讨论】:

    标签: ckeditor alignment config center


    【解决方案1】:

    在你的编辑config.js

    CKEDITOR.on( 'dialogDefinition', function( ev ) {
        // Take the dialog name and its definition from the event data.
        var dialogName = ev.data.name;
        var dialogDefinition = ev.data.definition;
    
        if ( dialogName == 'image2' ) {
    
            ev.data.definition.dialog.on('show', function() {
                //debugger;
                var widget = ev.data.definition.dialog.widget;
                // To prevent overwriting saved alignment
                if (widget.data['src'].length == 0)
                    widget.data['align'] = 'center';
    
            });
    
        }
    });
    

    享受吧!

    【讨论】:

      【解决方案2】:

      我已经成功使用上述解决方案几年了 - 尽管现在(CKEditor 版本 4.14.0)它会引发错误并且不再有效。在从这里公认的旧文档中进行了大量故障排除和帮助之后: https://nightly.ckeditor.com/20-05-20-06-04/standard/samples/old/dialog/dialog.html ...以下似乎在这里工作:

      在编辑器 config.js 文件中:

      CKEDITOR.on('dialogDefinition', function(ev) {
        let dialogName       = ev.data.name;
        let dialogDefinition = ev.data.definition;
        console.log(ev);
        if (dialogName == 'image2') {
          dialogDefinition.onFocus = function() {
            /**
             * 'none' is no good for us - if is none - reset to 'center'
             * if it's already 'left','center', or 'right' - leave alone.
             */
            if (this.getContentElement('info', 'align')
                .getValue() === 'none') {
              this.getContentElement('info', 'align')
                  .setValue('center');
            }
          };
        }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-13
        • 1970-01-01
        • 2012-07-28
        • 2017-01-08
        • 1970-01-01
        相关资源
        最近更新 更多