-
Notifications
You must be signed in to change notification settings - Fork 462
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
Comments
im having the same problem |
+1 |
2 similar comments
+1 |
+1 |
#10 , for the style attribute not response in the editor-change |
样式改变没响应,大神们,有解决的没? |
Anyone ever solve this issue? |
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: {}
}
}); |
Great! |
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,
}) |
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 Quilleditor-change
event).Demo
editor-change
triggerededitor-change
😭The text was updated successfully, but these errors were encountered: