Skip to content

Commit b581b35

Browse files
committed
Merge pull request #66 from ValeryYafremau/JS-339
JS-339: [SwatchRenderer.js] Preload images for all available options
2 parents e0efae1 + 76a5545 commit b581b35

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

app/code/Magento/Swatches/view/frontend/web/js/SwatchRenderer.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
define([
77
'jquery',
88
'underscore',
9+
'mage/gallery/preloadImages',
910
'jquery/ui'
10-
], function ($, _) {
11+
], function ($, _, preloadImages) {
1112
'use strict';
1213

1314
/**
@@ -268,6 +269,27 @@ define([
268269
'img': $main.find('.product-image-photo').attr('src')
269270
}];
270271
}
272+
this._preloadSwatchesImages();
273+
},
274+
275+
/**
276+
* Preloads optional configuration images.
277+
* @private
278+
*/
279+
_preloadSwatchesImages: function () {
280+
var options = this.options;
281+
282+
_.each(options.jsonConfig.images, function (array) {
283+
var fullImagesList = [],
284+
imagesList = [];
285+
286+
_.each(array, function (item) {
287+
imagesList.push(item.img);
288+
fullImagesList.push(item.full);
289+
});
290+
preloadImages(imagesList);
291+
preloadImages(fullImagesList);
292+
});
271293
},
272294

273295
/**

0 commit comments

Comments
 (0)