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

imageResizable style dimensions stripped on subsequent save #192

Closed
lukasgeiter opened this issue Dec 29, 2019 · 4 comments
Closed

imageResizable style dimensions stripped on subsequent save #192

lukasgeiter opened this issue Dec 29, 2019 · 4 comments

Comments

@lukasgeiter
Copy link

When using a redactor field with imageResizable enabled, resizing the image and then saving adds a style attribute to the <img> element which declares width and height of the image:

<img src="..." width="555" height="370" style="width: 555px; height: 370px;">

However whenever I save the entry without resizing the image, the style attribute is removed.

<img src="..." width="555" height="370">

I would expect the style attribute to remain the same when saving multiple times without making any changes. As a workaround, authors always have to remember to resize images slightly before saving to retain the attribute, which is far from ideal.

Steps to reproduce:

  1. Create entry with redactor field
  2. Add image to redactor field
  3. Resize the image
  4. Save > style attribute is set
  5. Save again (without resizing) > style attribute is removed

Versions:

Craft: 3.3.18.4
Redactor Plugin: 2.4.0

@lukasgeiter lukasgeiter changed the title imageResizable style dimensions stripped on second save imageResizable style dimensions stripped on subsequent save Dec 29, 2019
@chasegiunta
Copy link

@lukasgeiter you may want to ensure you don't have the "Remove inline styles" option checked in the advanced section of the field's settings.

image

@andris-sevcenko
Copy link
Contributor

I took a rather deep dive through Redactor's code. It appears that Redactor sanitizes the field value on load, which also includes removing the style attribute on all image tags. (source)

So, I went ahead and overrode that behavior, allowing the style attribute to stay on the img tags, since it's possible to remove them on save with field settings

@andris-sevcenko
Copy link
Contributor

This will be included in the next release!

@lukasgeiter
Copy link
Author

@andris-sevcenko Thanks!

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

3 participants