kensnyder / quill-image-resize-module

A module for Quill rich text editor to allow images to be resized.
MIT License
467 stars 468 forks source link

The onEditorChange was not triggered when I click a align button of this module #131

Open fred-hu opened 3 years ago

fred-hu commented 3 years ago

The onEditorChange was not triggered when I click a align button of this module,

Klipsik commented 3 years ago

You need an ovveride default quil image format method https://github.com/kensnyder/quill-image-resize-module/issues/10#issuecomment-317747389

var BaseImageFormat = Quill.import('formats/image');
const ImageFormatAttributesList = [
    'alt',
    'height',
    'width',
    'style'
];

class ImageFormat extends BaseImageFormat {
  static formats(domNode) {
    return ImageFormatAttributesList.reduce(function(formats, attribute) {
      if (domNode.hasAttribute(attribute)) {
        formats[attribute] = domNode.getAttribute(attribute);
      }
      return formats;
    }, {});
  }
  format(name, value) {
    if (ImageFormatAttributesList.indexOf(name) > -1) {
      if (value) {
        this.domNode.setAttribute(name, value);
      } else {
        this.domNode.removeAttribute(name);
      }
    } else {
      super.format(name, value);
    }
  }
}

Quill.register(ImageFormat, true);