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

Resizing an image in IE11 results sets different attributes than resizing an image in Chrome or Firefox #1412

Open
holatuwol opened this issue Jul 22, 2020 · 5 comments

Comments

@holatuwol
Copy link
Member

Do you want to request a feature or report a bug?
bug

What is the current behavior?

  • resizing an image in IE11 sets the style, height, and width attributes
  • resizing an image in Chrome or Firefox sets only the style attribute

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

  1. Open Chrome, resize the image in the demo site fullmoon.thumbnail.jpg and inspect the element, noticing there are no width and height attributes
  2. Open Firefox, resize the image in the demo site fullmoon.thumbnail.jpg and inspect the element, noticing there are no width and height attributes
  3. Open Firefox, resize the image in the demo site fullmoon.thumbnail.jpg and inspect the element, noticing there are width and height attributes

What is the expected behavior?

  1. Open Chrome, resize the image in the demo site fullmoon.thumbnail.jpg and inspect the element, noticing there are width and height attributes
  2. Open Firefox, resize the image in the demo site fullmoon.thumbnail.jpg and inspect the element, noticing there are width and height attributes
  3. Open Firefox, resize the image in the demo site fullmoon.thumbnail.jpg and inspect the element, noticing there are width and height attributes

Which versions of alloy-editor, and which browser / OS are affected by this issue? Did this work in previous versions?

holatuwol added a commit to holatuwol/alloy-editor that referenced this issue Jul 22, 2020
@duracell80
Copy link

duracell80 commented Jul 23, 2020

Perspective from the outside here. It's not so much that it's element vs inline style ... It could have both. What's actually happening is that the width for example is being set as 150px AND 75px at the same time. As an example.

What needs to happen if both width= and style=width: is used then both of those numbers need to match and both numbers need to be updated.

What's happening is that certain browsers are only acting on one thing, it should be both numbers being updated. This situation has been occuring for many years and our users HTML is full of dimensions that aren't matching.

It would be ideal also if particularly in DXP if we could know an audit of the edit, not just date modified but what environment was the user in when editing. Was it IE/Win, Chrome/Mac or Firefox/Linux and that could be set as a class on the content editable div with that user agent stored alongside the edit in the database.

That then gives me a good chance of using a class to attack the HTML with jQuery and fix the mismatch in dimensions in the DOM while Liferay nail this problem.

@duracell80
Copy link

duracell80 commented Jul 23, 2020

If I ever get a chance to write an Alloy Editor code content clean up script, I'll post it for consideration. The problem would be what size should the image be, if the width is 75px and 150px would the script choose the larger number? Which user was correct Sarah on IE or Terry on Chrome.

A "remove formatting" feature would at least give a user (or a support member fixing the issue for the user) the potential to clear the HTML and rebuild the content.

@holatuwol
Copy link
Member Author

The problem would be what size should the image be, if the width is 75px and 150px would the script choose the larger number? Which user was correct Sarah on IE or Terry on Chrome.

@duracell80 : My understanding is that the inline style should always have higher precedence, so regardless of the browser, a user would only see the changes if they update the inline style (attaching attributes when there is already an inline style would do nothing).

Viewing the following HTML file in different browsers consistently results in a very large empty image followed by a very small one.

<html><body>
	<img border=5 width=5 height=5 style="width: 500px; height: 500px" />
	<img border=5 width=500 height=500 style="width: 5px; height: 5px" /> 
</body></html>

The following Stackoverflow post also contains a useful link and explanation, since the specificity for the attribute value being zero means that any style (inline or not) would override the attribute.

As a result, even though the current behavior is inconsistent, it shouldn't have any actual end user impact, unless that end user is a developer inspecting the page.

@duracell80
Copy link

duracell80 commented Jul 23, 2020

Unfortunately there have been end user impacts between different users using different browsers to edit the same content. Sometimes causing different sizes in the saved content, sometimes causing the image resize plugin to refuse to work.

I've run into the opinion before that the "browser default" behaviour is correct ... But that can't be right because there are no web standards on this.

I think TinyMCE uses the HTML attributes and stays away from the inline styles but they do use inline styles for "image padding".

CKEditor ... I wasn't able to find any developer standards on how to output HTML when writing plugins, so the danger in relying on plugins is that fragmentation of standards. Developers have different styles, that's ok but there really needs to be a best practice understanding in in the developer community and a focus on code standards.

I would think a way forward would be for Liferay to lay down internal standards on how HTML should be created by the editor and test against that standard rather than defer to how the browser handles it. Maybe AntiSammy could enforce a HTML standard within DXP.

Having that standard could also help write a HTML clean up script. To be fair we have content created in Liferay 6 5+ years in the past, that content would still be edited in DXP 7 today.

It's not an easy task, some standards could help and considering "tag soup" just takes me back to the dangers of deferring to plugins and how browsers do things by default.

@duracell80
Copy link

But yeah width=50px and width=75px at the same time can't be considered ok.

wincent added a commit that referenced this issue Jul 27, 2020
fix: set width and height attributes for firefox and chrome (#1412)
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

2 participants