Skip to content

Commit e0efae1

Browse files
committed
Merge pull request #59 from ulaharbmg/JS-334
JS-334: Layout "jumps" on refresh while gallery is loading
2 parents 841bce8 + ab40ea1 commit e0efae1

File tree

5 files changed

+42
-23
lines changed

5 files changed

+42
-23
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
</div>
2121
</div>
2222
</div>
23+
<!--Fix for jumping content. Loader must be the same size as gallery.-->
24+
<script type="text/javascript">
25+
var config = {
26+
"width": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'width'); ?>,
27+
"thumbheight": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'height')
28+
?: $block->getImageAttribute('product_page_image_small', 'width'); ?>,
29+
"navtype": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/navtype"); ?>",
30+
"height": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_medium', 'height'); ?>
31+
},
32+
thumbBarHeight = 0,
33+
loader = document.querySelectorAll('[data-gallery-role="gallery-placeholder"] [data-role="loader"]')[0];
34+
35+
if (config.navtype === 'horizontal') {
36+
thumbBarHeight = config.thumbheight;
37+
}
38+
39+
loader.style.paddingBottom = ( config.height / config.width * 100) + "%";
40+
</script>
2341
<script type="text/x-magento-init">
2442
{
2543
"[data-gallery-role=gallery-placeholder]": {

lib/web/fotorama/fotorama.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ fotoramaVersion = '4.6.4';
8989

9090
horizontalImageClass = _fotoramaClass + '_horizontal_ratio',
9191
verticalImageClass = _fotoramaClass + '_vertical_ratio',
92-
93-
spinnerShowClass = _fotoramaClass + '_spinner';
92+
fotoramaSpinnerClass = _fotoramaClass + '__spinner',
93+
spinnerShowClass = fotoramaSpinnerClass + '--show';
9494
var JQUERY_VERSION = $ && $.fn.jquery.split('.');
9595

9696
if (!JQUERY_VERSION
@@ -1781,7 +1781,7 @@ fotoramaVersion = '4.6.4';
17811781
$videoClose = $fotorama.find(cls(videoCloseClass)),
17821782
videoClose = $videoClose[0],
17831783

1784-
$spinner = $fotorama.find('.fotorama_spin'),
1784+
$spinner = $fotorama.find(cls(fotoramaSpinnerClass)),
17851785

17861786
$videoPlaying,
17871787

lib/web/mage/gallery/gallery.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="fotorama__video-close"></div>
2121
<div class="fotorama__zoom-in" data-gallery-role="fotorama__zoom-in" aria-label="Zoom in" role="button" tabindex="0"></div>
2222
<div class="fotorama__zoom-out" data-gallery-role="fotorama__zoom-out" aria-label="Zoom out" role="button" tabindex="0"></div>
23-
<div class="fotorama_spin"></div>
23+
<div class="fotorama__spinner"></div>
2424
</div>
2525
<div class="fotorama__nav-wrap" data-gallery-role="nav-wrap">
2626
<div class="fotorama__nav fotorama__nav--thumbs">

lib/web/mage/gallery/gallery.less

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,6 @@
1313
@import 'module/_focus.less';
1414
@import 'module/_fullscreen.less';
1515

16-
.fotorama_spin {
17-
display: none;
18-
&.fotorama_spinner {
19-
display: block;
20-
width: 64px;
21-
height: 64px;
22-
background-image: url('@{baseDir}../images/loader-1.gif');
23-
bottom: 0;
24-
left: 0;
25-
margin: auto;
26-
position: absolute;
27-
right: 0;
28-
top: 0;
29-
z-index: @z-index-1;
30-
}
31-
}
32-
3316
.fotorama__zoom-in,
3417
.fotorama__zoom-out {
3518
display: none;
@@ -983,7 +966,7 @@
983966
.gallery-placeholder {
984967
.loading-mask {
985968
padding: 0 0 50%;
986-
position: absolute;
969+
position: static;
987970
}
988971
.loader img {
989972
position: absolute;
@@ -1003,3 +986,20 @@
1003986
}
1004987
}
1005988

989+
// Styles for spinner in gallery.
990+
.fotorama__spinner {
991+
display: none;
992+
width: @fotorama-spinner-size;
993+
height: @fotorama-spinner-size;
994+
background-image: url('@{baseDir}../images/loader-1.gif');
995+
bottom: 0;
996+
left: 0;
997+
margin: auto;
998+
position: absolute;
999+
right: 0;
1000+
top: 0;
1001+
z-index: @z-index-1;
1002+
&.fotorama__spinner--show {
1003+
display: block;
1004+
}
1005+
}

lib/web/mage/gallery/module/_variables.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
@size-fotorama-block: 80px;
1010
@fotorama-thumb-arrow: 30px;
1111
@fotorama-fullscreen-zoom-time: 0.3s;
12-
@fotorama-inner-box-shadow: 3px;
12+
@fotorama-inner-box-shadow: 3px;
13+
@fotorama-spinner-size: 64px;

0 commit comments

Comments
 (0)