Skip to content

Commit 53d03ee

Browse files
committed
Merge branch 'MAGETWO-45130' of github.corp.magento.com:magento-vanilla/magento2ce into PR
2 parents 93ab6e8 + d361e0a commit 53d03ee

File tree

1 file changed

+74
-30
lines changed

1 file changed

+74
-30
lines changed

lib/web/mage/gallery/gallery.js

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,48 @@ define([
1818
* Set main item first in order.
1919
* @param {Array.<Object>} data - Set of gallery items to update.
2020
*/
21-
var pushMainFirst = function(data){
22-
var mainIndex;
21+
var pushMainFirst = function (data) {
22+
var mainIndex;
23+
24+
if (!_.every(data, function (item) {
25+
return _.isObject(item);
26+
})
27+
) {
28+
return data;
29+
}
30+
31+
mainIndex = _.findIndex(data, function (item) {
32+
return item.isMain;
33+
});
34+
35+
if (mainIndex > -1) {
36+
data.unshift(data.splice(mainIndex, 1)[0]);
37+
}
2338

24-
if(!_.every(data, function(item){
25-
return _.isObject(item);
26-
}))
27-
{
2839
return data;
29-
}
40+
},
3041

31-
mainIndex = _.findIndex(data, function(item){
32-
return item.isMain;
33-
});
34-
if(mainIndex > -1){
35-
data.unshift(data.splice(mainIndex, 1)[0]);
36-
}
42+
/**
43+
* Helper for parse translate property
44+
*
45+
* @param {Element} el - el that to parse
46+
* @returns {Array} - array of properties.
47+
*/
48+
getTranslate = function (el) {
49+
var slideTransform = $(el).attr('style').split(';');
50+
51+
slideTransform = $.map(slideTransform, function (style) {
52+
style = style.trim();
53+
54+
if (style.startsWith('transform: translate3d')) {
55+
return style.match(/transform: translate3d\((.+)px,(.+)px,(.+)px\)/);
56+
}
57+
58+
return false;
59+
});
3760

38-
return data;
39-
};
61+
return slideTransform.filter(Boolean);
62+
};
4063

4164
return Class.extend({
4265

@@ -60,6 +83,8 @@ define([
6083
* @param {String} element - String selector of gallery DOM element.
6184
*/
6285
initialize: function (config, element) {
86+
var self = this;
87+
6388
this._super();
6489

6590
_.bindAll(this,
@@ -71,6 +96,7 @@ define([
7196

7297
this.settings = {
7398
$element: $(element),
99+
$pageWrapper: $('body>.page-wrapper'),
74100
currentConfig: config,
75101
defaultConfig: _.clone(config),
76102
fullscreenConfig: _.clone(config.fullscreen),
@@ -90,25 +116,46 @@ define([
90116
this.initApi();
91117
this.setupBreakpoints();
92118
this.initFullscreenSettings();
119+
93120
this.settings.$element.on('mouseup', '.fotorama__stage__frame', function () {
94-
if (!$(this).parents('.fotorama__shadows--left').length) {
95-
$('[data-gallery-role="gallery"]').data('fotorama').requestFullScreen();
96-
$('[data-gallery-role="fotorama__fullscreen-icon"]').css({
97-
opacity: 1,
98-
visibility: 'visible',
99-
display: 'block'
100-
});
121+
if (
122+
!$(this).parents('.fotorama__shadows--left, .fotorama__shadows--right').length &&
123+
!$(this).hasClass('fotorama-video-container')
124+
) {
125+
self.openFullScreen();
101126
}
102127
});
128+
129+
if (this.isTouchEnabled) {
130+
this.settings.$element.on('tap', '.fotorama__stage__frame', function () {
131+
var translate = getTranslate($(this).parents('.fotorama__stage__shaft'));
132+
133+
if (translate[1] === '0' && !$(this).hasClass('fotorama-video-container')) {
134+
self.openFullScreen();
135+
self.settings.$pageWrapper.hide();
136+
}
137+
});
138+
}
139+
},
140+
141+
/**
142+
* Open gallery fullscreen
143+
*/
144+
openFullScreen: function () {
145+
this.settings.api.fotorama.requestFullScreen();
146+
this.settings.$fullscreenIcon.css({
147+
opacity: 1,
148+
visibility: 'visible',
149+
display: 'block'
150+
});
103151
},
104152

105153
/**
106154
* Gallery fullscreen settings.
107155
*/
108156
initFullscreenSettings: function () {
109157
var settings = this.settings,
110-
self = this,
111-
items = [];
158+
self = this;
112159

113160
settings.$gallery = this.settings.$element.find('[data-gallery-role="gallery"]');
114161
settings.$fullscreenIcon = this.settings.$element.find('[data-gallery-role="fotorama__fullscreen-icon"]');
@@ -131,6 +178,7 @@ define([
131178
});
132179

133180
settings.$gallery.on('fotorama:fullscreenexit', function () {
181+
settings.$pageWrapper.show();
134182
settings.api.updateOptions(settings.defaultConfig.options, true);
135183
settings.focusableStart.unbind('focusin', this._focusSwitcher);
136184
settings.focusableEnd.unbind('focusin', this._focusSwitcher);
@@ -165,10 +213,6 @@ define([
165213
* focusable element in modal window scope.
166214
* If position is "start" - sets focus to last
167215
* focusable element in modal window scope
168-
*
169-
* @param {String} type - can be "opened" or false
170-
* If type is "opened" - looks to "this.options.focus"
171-
* property and sets focus
172216
*/
173217
_setFocus: function (position) {
174218
var settings = this.settings,
@@ -199,6 +243,7 @@ define([
199243
if (settings.breakpoints) {
200244
_.each(_.values(settings.breakpoints), function (breakpoint) {
201245
var conditions;
246+
202247
_.each(_.pairs(breakpoint.conditions), function (pair) {
203248
conditions = conditions ? conditions + ' and (' + pair[0] + ': ' + pair[1] + ')' :
204249
'(' + pair[0] + ': ' + pair[1] + ')';
@@ -233,8 +278,7 @@ define([
233278
var pairs,
234279
settings = this.settings,
235280
config = this.config,
236-
startConfig = this.startConfig,
237-
triggeredBreakpoints = 0;
281+
startConfig = this.startConfig;
238282

239283
if (_.isObject(settings.breakpoints)) {
240284
pairs = _.pairs(settings.breakpoints);

0 commit comments

Comments
 (0)