Skip to content

Commit a63e681

Browse files
committed
Trigger styles update on last loaded image event
1 parent a0ed711 commit a63e681

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

app/code/Magento/Ui/view/base/web/js/grid/columns/image.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ define([
1111
defaults: {
1212
bodyTmpl: 'ui/grid/columns/image',
1313
modules: {
14+
masonry: '${ $.parentName }',
1415
previewComponent: '${ $.parentName }.preview'
1516
},
1617
previewRowId: null,
@@ -35,6 +36,15 @@ define([
3536
return this;
3637
},
3738

39+
/**
40+
* Updates styles when image loaded.
41+
*
42+
* @param {Object} record
43+
*/
44+
updateStyles: function (record) {
45+
!record.lastInRow || this.masonry().updateStyles();
46+
},
47+
3848
/**
3949
* Returns url to given record.
4050
*

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ define([
101101
this.imageMargin = parseInt(this.imageMargin, 10);
102102
this.container = $('[data-id="' + this.containerId + '"]')[0];
103103

104-
this.setLayoutStyles();
105104
this.setEventListener();
105+
this.setLayoutStyles();
106106

107107
return this;
108108
},
@@ -112,18 +112,25 @@ define([
112112
*/
113113
setEventListener: function () {
114114
window.addEventListener('resize', function () {
115-
raf(function () {
116-
this.containerWidth = window.innerWidth;
117-
this.setLayoutStyles();
118-
}.bind(this), this.refreshFPS);
115+
this.updateStyles();
119116
}.bind(this));
120117
},
121118

119+
/**
120+
* Updates styles for component.
121+
*/
122+
updateStyles: function () {
123+
raf(function () {
124+
this.containerWidth = window.innerWidth;
125+
this.setLayoutStyles();
126+
}.bind(this), this.refreshFPS);
127+
},
128+
122129
/**
123130
* Set layout styles inside the container
124131
*/
125132
setLayoutStyles: function () {
126-
var containerWidth = parseInt(this.container.clientWidth, 10) - 15,
133+
var containerWidth = parseInt(this.container.clientWidth, 10),
127134
rowImages = [],
128135
ratio = 0,
129136
rowHeight = 0,

app/code/Magento/Ui/view/base/web/templates/grid/columns/image.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
*/
66
-->
77
<div class="masonry-image-block" ko-style="$col.getStyles($row())" css="{'active': $col.getIsActive($row())}" attr="'data-id': $col.getId($row())">
8-
<img attr="src: $col.getUrl($row())" css="$col.getClasses($row())" click="function(){ expandPreview($row()) }" data-role="thumbnail"/>
8+
<img data-bind="event: { load: updateStyles($row()) }" attr="src: $col.getUrl($row())" css="$col.getClasses($row())" click="function(){ expandPreview($row()) }" data-role="thumbnail"/>
99
</div>

0 commit comments

Comments
 (0)