Skip to content

Commit a4e80c2

Browse files
AC-10845::Pagebuilder banner image not visible in gallery
1 parent 367049e commit a4e80c2

File tree

2 files changed

+43
-40
lines changed
  • app/code/Magento/Ui/view/base/web/js/grid
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid

2 files changed

+43
-40
lines changed

app/code/Magento/Ui/view/base/web/js/grid/masonry.js

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ define([
77
'Magento_Ui/js/lib/view/utils/raf',
88
'jquery',
99
'ko',
10-
'underscore',
11-
'domReady!'
10+
'underscore'
1211
], function (Listing, raf, $, ko, _) {
1312
'use strict';
1413

@@ -101,7 +100,7 @@ define([
101100
}
102101
this.imageMargin = parseInt(this.imageMargin, 10);
103102
this.container = $('[data-id="' + this.containerId + '"]')[0];
104-
this.setLayoutStylesWhenLoaded();
103+
this.setLayoutStyles();
105104
this.setEventListener();
106105

107106
return this;
@@ -129,38 +128,42 @@ define([
129128
/**
130129
* Set layout styles inside the container
131130
*/
132-
setLayoutStyles: function () {
133-
var containerWidth = parseInt(this.container.clientWidth, 10),
134-
rowImages = [],
135-
ratio = 0,
136-
rowHeight = 0,
137-
calcHeight = 0,
138-
isLastRow = false,
139-
rowNumber = 1;
140-
141-
this.setMinRatio();
142-
143-
this.rows().forEach(function (image, index) {
144-
ratio += parseFloat((image.width / image.height).toFixed(2));
145-
rowImages.push(image);
146-
147-
if (ratio < this.minRatio && index + 1 !== this.rows().length) {
148-
// Row has more space for images and the image is not the last one - proceed to the next iteration
149-
return;
150-
}
151-
152-
ratio = Math.max(ratio, this.minRatio);
153-
calcHeight = (containerWidth - this.imageMargin * rowImages.length) / ratio;
154-
rowHeight = calcHeight < this.maxImageHeight ? calcHeight : this.maxImageHeight;
155-
isLastRow = index + 1 === this.rows().length;
156-
157-
this.assignImagesToRow(rowImages, rowNumber, rowHeight, isLastRow);
158-
159-
rowImages = [];
160-
ratio = 0;
161-
rowNumber++;
162-
163-
}.bind(this));
131+
setLayoutStyles: function (callback) {
132+
if (typeof this.container != 'undefined') {
133+
var containerWidth = parseInt(this.container.clientWidth, 10),
134+
rowImages = [],
135+
ratio = 0,
136+
rowHeight = 0,
137+
calcHeight = 0,
138+
isLastRow = false,
139+
rowNumber = 1;
140+
141+
this.setMinRatio();
142+
143+
this.rows().forEach(function (image, index) {
144+
ratio += parseFloat((image.width / image.height).toFixed(2));
145+
rowImages.push(image);
146+
147+
if (ratio < this.minRatio && index + 1 !== this.rows().length) {
148+
// Row has more space for images and the image is not the last one - proceed to the next iteration
149+
return;
150+
}
151+
152+
ratio = Math.max(ratio, this.minRatio);
153+
calcHeight = (containerWidth - this.imageMargin * rowImages.length) / ratio;
154+
rowHeight = calcHeight < this.maxImageHeight ? calcHeight : this.maxImageHeight;
155+
isLastRow = index + 1 === this.rows().length;
156+
157+
this.assignImagesToRow(rowImages, rowNumber, rowHeight, isLastRow);
158+
159+
rowImages = [];
160+
ratio = 0;
161+
rowNumber++;
162+
163+
}.bind(this));
164+
} else {
165+
setTimeout(callback, 0);
166+
}
164167
},
165168

166169
/**
@@ -194,9 +197,9 @@ define([
194197
if (typeof this.container === 'undefined') {
195198
setTimeout(function () {
196199
this.waitForContainer(callback);
197-
}.bind(this), 1000);
200+
}.bind(this), 500);
198201
} else {
199-
setTimeout(callback, 0);
202+
setTimeout(callback, 500);
200203
}
201204
},
202205

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/masonry.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ define([
6060
});
6161

6262
describe('check initComponent', function () {
63-
it('verify setLayoutStylesWhenLoaded called and grid iniztilized', function () {
64-
var setlayoutStyles = spyOn(Component, 'setLayoutStylesWhenLoaded');
63+
it('verify setLayoutstyles called and grid iniztilized', function () {
64+
var setlayoutStyles = spyOn(Component, 'setLayoutstyles');
6565

6666
Object.defineProperty(Component.container, 'clientWidth', {value: '', configurable: true});
6767
expect(Component).toBeDefined();
@@ -74,7 +74,7 @@ define([
7474
expect(setlayoutStyles).toHaveBeenCalled();
7575
});
7676
it('verify events triggered', function () {
77-
var setLayoutStyles = spyOn(Component, 'setLayoutStylesWhenLoaded');
77+
var setLayoutStyles = spyOn(Component, 'setLayoutstyles');
7878

7979
Component.initComponent(rows);
8080
Component.container = {};

0 commit comments

Comments
 (0)