我目前正在将所有TinyMCE插件迁移到CKeditor,并且使用InsertInline插件时遇到问题 .

在TinyMCE中,我有一个这样的代码:

(function ($) {
Drupal.wysiwyg.plugins['insertinline'] = {

  /**
   * Return whether the passed node belongs to this plugin.
   */
  isNode: function(node) {
    return ($(node).is('img.wysiwyg-inline-image'));
  },


  /**
   * Execute the button.
   */
  invoke: function(data, settings, instanceId) {
    alert(Drupal.t('This is a pseudo plugin/button.\nIt does not insert an inline image.\n\nPlease use the INSERT button from the image upload fieldset.'));
  },


  /**
   * Replace all <!-- INLINE:xxx;w=x;h=x --> tags with images.
   */
  attach: function(content, settings, instanceId) {
    that = this;

    // Replace inline images with physical image
    content = content.replace(new RegExp('<!-- INLINE:([0-9]*);w=([0-9]*);h=([0-9]*) -->', 'gi'), function($0, $1, $2, $3) { return that._getPlaceholder($1, $2, $3); });

    return content;
  },


  /**
   * Replace images with <!-- INLINE:xxx;w=x;h=x --> tags in content upon detaching editor.
   */
  detach: function(content, settings, instanceId) {
    var $content = $('<div>' + content + '</div>'); // No .outerHTML() in jQuery :(

    $.each($('img.wysiwyg-inline-image', $content), function (i, elem) {
      altText = ' ' + Drupal.checkPlain(elem.getAttribute('alt')) + ' ';

      if (elem.parentNode && elem.parentNode.parentNode && elem.parentNode.tagName == 'H2') {
        // Moving the current element to left side of H2 tag 
        elem.parentNode.parentNode.insertBefore(document.createComment(altText), elem.parentNode);
        elem.parentNode.removeChild(elem);
      }
      else {
        elem.parentNode.insertBefore(document.createComment(altText), elem);
        elem.parentNode.removeChild(elem);
      }
    });
    return $content.html();
  },


  /**
   * Helper function to return a HTML placeholder.
   */
  _getPlaceholder: function (fid, w, h) {
    if (!fid) {
      fid = '';
    }
    if (!w) {
      w = '240';
    }
    if (!h) {
      h = '240';
    }

    // Grab image detail data
    var imgData = Drupal.cnngo_inline.getInlineImageDetail(fid, w, h);

    // Build and return image tag
    return '<img src="' + imgData.src + '" alt="' + imgData.alt + '" title="' + imgData.title + '" class="wysiwyg-inline-image" width="' + w + '" height="' + h + '" />';
  }
};
})(jQuery);

How it works:

假设我上传了一个600x600像素图片并将其插入WYSIWYG区域,默认情况下会插入一个img标签

enter image description here

当我单击图像中所述的“插入”按钮时 . 它会像这样插入img标签

<img class="wysiwyg-inline-image" title="Inline image 240x240" src="http://mydomain.com/sites/default/files/styles/inline_image_temp_240x240/public/2013/05/28/600x600_1.png" alt="INLINE:142879;w=240;h=240" width="240" height="240" data-mce-src="http://mydomain.com/sites/default/files/styles/inline_image_temp_240x240/public/2013/05/28/600x600_1.png">

见下图 .

enter image description here

现在,如果我要分离编辑器(单击切换到纯文本),img标记将替换为

<p><!-- INLINE:142879;w=240;h=240 --></p>

enter image description here

当我重新打开编辑器时,它将显示img标签(将呈现img) .

有人能指出我在Ckeditor中相当于disct / attach的正确方向 .

我花了几个小时在谷歌但找不到确切的答案(也许我的问题不对) .