Skip to content

Commit

Permalink
Trigger styles update on last loaded image event
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar65 committed May 27, 2020
1 parent a0ed711 commit a63e681
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
10 changes: 10 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/grid/columns/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define([
defaults: {
bodyTmpl: 'ui/grid/columns/image',
modules: {
masonry: '${ $.parentName }',
previewComponent: '${ $.parentName }.preview'
},
previewRowId: null,
Expand All @@ -35,6 +36,15 @@ define([
return this;
},

/**
* Updates styles when image loaded.
*
* @param {Object} record
*/
updateStyles: function (record) {
!record.lastInRow || this.masonry().updateStyles();
},

/**
* Returns url to given record.
*
Expand Down
19 changes: 13 additions & 6 deletions app/code/Magento/Ui/view/base/web/js/grid/masonry.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ define([
this.imageMargin = parseInt(this.imageMargin, 10);
this.container = $('[data-id="' + this.containerId + '"]')[0];

this.setLayoutStyles();
this.setEventListener();
this.setLayoutStyles();

return this;
},
Expand All @@ -112,18 +112,25 @@ define([
*/
setEventListener: function () {
window.addEventListener('resize', function () {
raf(function () {
this.containerWidth = window.innerWidth;
this.setLayoutStyles();
}.bind(this), this.refreshFPS);
this.updateStyles();
}.bind(this));
},

/**
* Updates styles for component.
*/
updateStyles: function () {
raf(function () {
this.containerWidth = window.innerWidth;
this.setLayoutStyles();
}.bind(this), this.refreshFPS);
},

/**
* Set layout styles inside the container
*/
setLayoutStyles: function () {
var containerWidth = parseInt(this.container.clientWidth, 10) - 15,
var containerWidth = parseInt(this.container.clientWidth, 10),
rowImages = [],
ratio = 0,
rowHeight = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/
-->
<div class="masonry-image-block" ko-style="$col.getStyles($row())" css="{'active': $col.getIsActive($row())}" attr="'data-id': $col.getId($row())">
<img attr="src: $col.getUrl($row())" css="$col.getClasses($row())" click="function(){ expandPreview($row()) }" data-role="thumbnail"/>
<img data-bind="event: { load: updateStyles($row()) }" attr="src: $col.getUrl($row())" css="$col.getClasses($row())" click="function(){ expandPreview($row()) }" data-role="thumbnail"/>
</div>

0 comments on commit a63e681

Please sign in to comment.