Skip to content

Commit 5a0f754

Browse files
authored
ENGCOM-6376: Prevent page scroll jumping when product gallery loads #25385
2 parents ddecf6b + f805cf0 commit 5a0f754

File tree

3 files changed

+107
-4
lines changed

3 files changed

+107
-4
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable max-nested-callbacks */
7+
define([
8+
'mage/gallery/gallery',
9+
'jquery'
10+
], function (Gallery, $) {
11+
'use strict';
12+
13+
var gallery,
14+
options,
15+
element,
16+
jqueryDataMock,
17+
originSpy;
18+
19+
beforeEach(function () {
20+
options = {
21+
options: {
22+
allowfullscreen: true,
23+
arrows: true,
24+
height: 700,
25+
keyboard: true,
26+
loop: true,
27+
nav: 'thumbs',
28+
navarrows: true,
29+
navdir: 'horizontal',
30+
navtype: 'slides',
31+
showCaption: false,
32+
thumbheight: 110,
33+
thumbwidth: 88,
34+
transition: 'slide',
35+
transitionduration: 500,
36+
width: 700
37+
},
38+
fullscreen: {
39+
arrows: true,
40+
loop: true,
41+
nav: 'thumbs',
42+
navarrows: false,
43+
navdir: 'horizontal',
44+
navtype: 'slides',
45+
showCaption: false,
46+
transition: 'slide',
47+
transitionduration: 500
48+
},
49+
breakpoints: {
50+
mobile: {}
51+
},
52+
data: [
53+
{
54+
caption: 'Simple product',
55+
isMain: true,
56+
position: '1',
57+
type: 'image',
58+
videoUrl: null,
59+
thumb: '',
60+
full: '',
61+
img: ''
62+
}
63+
],
64+
magnifierOpts: {
65+
enabled: false,
66+
eventType: 'hover',
67+
fullscreenzoom: '20',
68+
height: 100,
69+
largeWrapper: '[data-gallery-role=\'magnifier\']',
70+
left: 10,
71+
mode: 'outside',
72+
thumb: '.fotorama__img',
73+
top: 10,
74+
width: 100,
75+
zoomable: false
76+
}
77+
};
78+
element = $('<div class="gallery-placeholder' +
79+
' _block-content-loading" data-gallery-role="gallery-placeholder">' +
80+
'<img alt="main product photo" class="gallery-placeholder__image" src="">' +
81+
'</div>');
82+
});
83+
84+
describe('"initGallery" method', function () {
85+
it('Verify gallery initialization', function () {
86+
originSpy = $.fn.data;
87+
jqueryDataMock = {
88+
setOptions: jasmine.createSpy().and.returnValue(true),
89+
updateOptions: jasmine.createSpy().and.returnValue(true)
90+
};
91+
spyOn($.fn, 'data').and.callFake(function () {
92+
return jqueryDataMock;
93+
});
94+
95+
gallery = new Gallery(options, element);
96+
expect(gallery.settings.$elementF.class).toBe(element[1]);
97+
expect(gallery.settings.fullscreenConfig).toBeDefined();
98+
expect(gallery.settings.fotoramaApi).toBeDefined();
99+
expect(gallery.settings.data).toBeDefined();
100+
expect(gallery.settings.api).toBeDefined();
101+
102+
$.fn.data = originSpy;
103+
});
104+
});
105+
});

lib/web/fotorama/fotorama.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,13 +3275,9 @@ fotoramaVersion = '4.6.4';
32753275

32763276
if (measureIsValid(width)) {
32773277
$wrap.css({width: ''});
3278-
$wrap.css({height: ''});
32793278
$stage.css({width: ''});
3280-
$stage.css({height: ''});
32813279
$stageShaft.css({width: ''});
3282-
$stageShaft.css({height: ''});
32833280
$nav.css({width: ''});
3284-
$nav.css({height: ''});
32853281
$wrap.css({minWidth: measures.minwidth || 0, maxWidth: measures.maxwidth || MAX_WIDTH});
32863282

32873283
if (o_nav === 'dots') {

lib/web/mage/gallery/gallery.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ define([
291291
config.click = false;
292292
config.breakpoints = null;
293293
settings.currentConfig = config;
294+
settings.$element.css('min-height', settings.$element.height());
294295
settings.$element.html(tpl);
295296
settings.$element.removeClass('_block-content-loading');
296297
settings.$elementF = $(settings.$element.children()[0]);
297298
settings.$elementF.fotorama(config);
299+
settings.$element.css('min-height', '');
298300
settings.fotoramaApi = settings.$elementF.data('fotorama');
299301
$.extend(true, config, this.startConfig);
300302

0 commit comments

Comments
 (0)