Skip to content

Commit 5e64bde

Browse files
MC-41569: "Image Size" sporadically changing from "%" to pixels
1 parent 7e8dfeb commit 5e64bde

File tree

2 files changed

+31
-2
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/utils
  • dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/adminhtml/web/js/utils

2 files changed

+31
-2
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/utils/editor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ export function parseAttributesString(attributes: string): { [key: string]: stri
171171
*/
172172
export function lockImageSize(element: HTMLElement) {
173173
[].slice.call(element.querySelectorAll("img")).forEach((image: HTMLImageElement) => {
174-
image.style.width = `${image.width}px`;
175-
image.style.height = `${image.height}px`;
174+
if (image.style.width.length === 0 && image.style.height.length === 0) {
175+
image.style.width = `${image.width}px`;
176+
image.style.height = `${image.height}px`;
177+
}
176178
});
177179
}
178180

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_PageBuilder/js/utils/editor',
8+
'jquery'
9+
], function (utils, $) {
10+
'use strict';
11+
12+
describe('Magento_PageBuilder/js/utils/editor.js', function () {
13+
describe('lockImageSize', function () {
14+
it('Should not change the defined image sizes', function () {
15+
var image = new Image();
16+
17+
$(document.body).append(image);
18+
$(image).width('100%');
19+
20+
utils.lockImageSize(document.body);
21+
expect(image.style.width).toEqual('100%');
22+
23+
image.remove();
24+
});
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)