Skip to content

Commit d06fd27

Browse files
committed
Get width including scroll bar
1 parent 1d0316d commit d06fd27

File tree

1 file changed

+18
-31
lines changed
  • app/code/Magento/Ui/view/base/web/js/grid

1 file changed

+18
-31
lines changed

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

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,10 @@ define([
9898
if (!rows.length) {
9999
return;
100100
}
101-
102-
//initialize row observables
103-
this.rows().forEach(function (image) {
104-
image.styles = ko.observable({});
105-
image.css = ko.observable({});
106-
});
107-
108101
this.imageMargin = parseInt(this.imageMargin, 10);
109102
this.container = $('[data-id="' + this.containerId + '"]')[0];
110103

111-
this.setLayoutStylesWhenLoaded();
104+
this.setLayoutStyles();
112105
this.setEventListener();
113106

114107
return this;
@@ -130,7 +123,7 @@ define([
130123
* Set layout styles inside the container
131124
*/
132125
setLayoutStyles: function () {
133-
var containerWidth = parseInt(this.container.clientWidth, 10),
126+
var containerWidth = parseInt(this.container.clientWidth, 10) - 15,
134127
rowImages = [],
135128
ratio = 0,
136129
rowHeight = 0,
@@ -188,37 +181,25 @@ define([
188181
},
189182

190183
/**
191-
* Call method when condition is true
184+
* Wait for container to initialize
192185
*/
193-
conditionCallback: function (condition, callback) {
194-
if (condition()) {
186+
waitForContainer: function (callback) {
187+
if (typeof this.container === 'undefined') {
195188
setTimeout(function () {
196-
this.conditionCallback(condition, callback);
197-
}.bind(this), 100);
189+
this.waitForContainer(callback);
190+
}.bind(this), 500);
198191
} else {
199-
callback();
192+
setTimeout(callback, 0);
200193
}
201194
},
202195

203196
/**
204-
* Set layout styles when last image in grid is loaded.
197+
* Set layout styles when container element is loaded.
205198
*/
206199
setLayoutStylesWhenLoaded: function () {
207-
var images = '[data-id="' + this.containerId + '"] img';
208-
209-
this.conditionCallback(
210-
function () {
211-
return $(images).length === 0;
212-
},
213-
function () {
214-
$(images).last().load(function () {
215-
this.setLayoutStyles();
216-
}.bind(this)).each(function () {
217-
if (this.complete) {
218-
$(this).load();
219-
}
220-
});
221-
}.bind(this));
200+
this.waitForContainer(function () {
201+
this.setLayoutStyles();
202+
}.bind(this));
222203
},
223204

224205
/**
@@ -229,6 +210,9 @@ define([
229210
* @param {Number} height
230211
*/
231212
setImageStyles: function (img, width, height) {
213+
if (!img.styles) {
214+
img.styles = ko.observable();
215+
}
232216
img.styles({
233217
width: parseInt(width, 10) + 'px',
234218
height: parseInt(height, 10) + 'px'
@@ -242,6 +226,9 @@ define([
242226
* @param {Object} classes
243227
*/
244228
setImageClass: function (image, classes) {
229+
if (!image.css) {
230+
image.css = ko.observable(classes);
231+
}
245232
image.css(classes);
246233
},
247234

0 commit comments

Comments
 (0)