|
7 | 7 | 'Magento_Ui/js/lib/view/utils/raf', |
8 | 8 | 'jquery', |
9 | 9 | 'ko', |
10 | | - 'underscore', |
11 | | - 'domReady!' |
| 10 | + 'underscore' |
12 | 11 | ], function (Listing, raf, $, ko, _) { |
13 | 12 | 'use strict'; |
14 | 13 |
|
@@ -101,7 +100,7 @@ define([ |
101 | 100 | } |
102 | 101 | this.imageMargin = parseInt(this.imageMargin, 10); |
103 | 102 | this.container = $('[data-id="' + this.containerId + '"]')[0]; |
104 | | - this.setLayoutStylesWhenLoaded(); |
| 103 | + this.setLayoutStyles(); |
105 | 104 | this.setEventListener(); |
106 | 105 |
|
107 | 106 | return this; |
@@ -129,38 +128,42 @@ define([ |
129 | 128 | /** |
130 | 129 | * Set layout styles inside the container |
131 | 130 | */ |
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 | + } |
164 | 167 | }, |
165 | 168 |
|
166 | 169 | /** |
@@ -194,9 +197,9 @@ define([ |
194 | 197 | if (typeof this.container === 'undefined') { |
195 | 198 | setTimeout(function () { |
196 | 199 | this.waitForContainer(callback); |
197 | | - }.bind(this), 1000); |
| 200 | + }.bind(this), 500); |
198 | 201 | } else { |
199 | | - setTimeout(callback, 0); |
| 202 | + setTimeout(callback, 500); |
200 | 203 | } |
201 | 204 | }, |
202 | 205 |
|
|
0 commit comments