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

Image position not saved #139

Open
cramy25 opened this issue Jan 5, 2022 · 4 comments
Open

Image position not saved #139

cramy25 opened this issue Jan 5, 2022 · 4 comments

Comments

@cramy25
Copy link

cramy25 commented Jan 5, 2022

Hi,
If I select the image position and close my admin page all is working well, but if I reopen my admin page to do some modification, the position of the image is going back to the left.

Is there a way to keep the position I selected?

@toregua
Copy link

toregua commented Oct 25, 2022

same behavior for me, the image position is not persisted when i save my generated html and reload quill component with the same html, images positions are lost

it seems related to this issue

@toregua
Copy link

toregua commented Oct 25, 2022

I have found a solution related to #10. It is due to inline css that are not persisted

Solution :

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

class ImageFormat extends BaseImageFormat {
    domNode: any;

    static formats(domNode) {
        // tslint:disable-next-line: only-arrow-functions
        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);

@okjack365
Copy link

That's because you didn't save the style of the picture to your editor data.
formats: ['image', 'width'] may be needed.
Also see #10

@bijaypoudel1
Copy link

I have found a solution related to #10. It is due to inline css that are not persisted

Solution :

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

class ImageFormat extends BaseImageFormat {
    domNode: any;

    static formats(domNode) {
        // tslint:disable-next-line: only-arrow-functions
        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);

It's working for me after wasting few hours. Thansk

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

4 participants