Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger 'editor-change' when user changes image alignment #31

Open
sotaan opened this issue Jan 24, 2018 · 10 comments
Open

Trigger 'editor-change' when user changes image alignment #31

sotaan opened this issue Jan 24, 2018 · 10 comments

Comments

@sotaan
Copy link

sotaan commented Jan 24, 2018

Description

I scratched my head for hours to verify this before even posting.
I founded out that when a user interacts with the alignment Toolbar, there is no 'editor-change' event being triggered.
I can be a problem when a user change alignment as final action since it will not be registered by my Vue component (I rely on a change event bound to Quill editor-change event).

Demo

  1. open this plunkr
  2. open dev console
  3. try resizing an image: editor-change triggered
  4. try changing alignment: no editor-change 😭
@sotaan sotaan changed the title Trigger 'editor-change' when user changes alignment Trigger 'editor-change' when user changes image alignment Jan 26, 2018
@jagabs
Copy link

jagabs commented Mar 25, 2018

im having the same problem

@jsiebern
Copy link

jsiebern commented May 8, 2018

+1

2 similar comments
@ccbikai
Copy link

ccbikai commented Jul 18, 2018

+1

@WinnieFE
Copy link

WinnieFE commented Dec 6, 2018

+1

@shmilyoo
Copy link

#10 , for the style attribute not response in the editor-change

@zhenglixin1
Copy link

样式改变没响应,大神们,有解决的没?

@benwinding
Copy link

Anyone ever solve this issue?

@benwinding
Copy link

Okay, we solved this issue by adding the code from this comment: #10 (comment)

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);
                
                
var quill = new Quill('#editor', {
    theme: 'snow',
    modules: {
        imageResize: {}
    }
});

@ghost
Copy link

ghost commented Oct 29, 2019

Great!
I saw your message just ago.
Good luck!

@dschissler
Copy link

You can use a mutation observer with a debounced callback to obtain any change which occurred to the HTML in the editor. The only possible downside is that it could trigger on something like the resize grabbers and alignment overlay appearing. Also make sure to disconnect the observer to prevent possible memory leaks.

    const editor = new Quill(...)

    const mutationObserver = new MutationObserver(debounce(() => {
      console.log(editor.root.innerHTML)
    }, 200))

    mutationObserver.observe(editor.root, {
      attributes: true,
      characterData: true,
      childList: true,
      subtree: true,
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants