@@ -18,25 +18,48 @@ define([
18
18
* Set main item first in order.
19
19
* @param {Array.<Object> } data - Set of gallery items to update.
20
20
*/
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
+ }
23
38
24
- if ( ! _ . every ( data , function ( item ) {
25
- return _ . isObject ( item ) ;
26
- } ) )
27
- {
28
39
return data ;
29
- }
40
+ } ,
30
41
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 ( / t r a n s f o r m : t r a n s l a t e 3 d \( ( .+ ) p x , ( .+ ) p x , ( .+ ) p x \) / ) ;
56
+ }
57
+
58
+ return false ;
59
+ } ) ;
37
60
38
- return data ;
39
- } ;
61
+ return slideTransform . filter ( Boolean ) ;
62
+ } ;
40
63
41
64
return Class . extend ( {
42
65
@@ -60,6 +83,8 @@ define([
60
83
* @param {String } element - String selector of gallery DOM element.
61
84
*/
62
85
initialize : function ( config , element ) {
86
+ var self = this ;
87
+
63
88
this . _super ( ) ;
64
89
65
90
_ . bindAll ( this ,
@@ -71,6 +96,7 @@ define([
71
96
72
97
this . settings = {
73
98
$element : $ ( element ) ,
99
+ $pageWrapper : $ ( 'body>.page-wrapper' ) ,
74
100
currentConfig : config ,
75
101
defaultConfig : _ . clone ( config ) ,
76
102
fullscreenConfig : _ . clone ( config . fullscreen ) ,
@@ -90,25 +116,46 @@ define([
90
116
this . initApi ( ) ;
91
117
this . setupBreakpoints ( ) ;
92
118
this . initFullscreenSettings ( ) ;
119
+
93
120
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 ( ) ;
101
126
}
102
127
} ) ;
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
+ } ) ;
103
151
} ,
104
152
105
153
/**
106
154
* Gallery fullscreen settings.
107
155
*/
108
156
initFullscreenSettings : function ( ) {
109
157
var settings = this . settings ,
110
- self = this ,
111
- items = [ ] ;
158
+ self = this ;
112
159
113
160
settings . $gallery = this . settings . $element . find ( '[data-gallery-role="gallery"]' ) ;
114
161
settings . $fullscreenIcon = this . settings . $element . find ( '[data-gallery-role="fotorama__fullscreen-icon"]' ) ;
@@ -131,6 +178,7 @@ define([
131
178
} ) ;
132
179
133
180
settings . $gallery . on ( 'fotorama:fullscreenexit' , function ( ) {
181
+ settings . $pageWrapper . show ( ) ;
134
182
settings . api . updateOptions ( settings . defaultConfig . options , true ) ;
135
183
settings . focusableStart . unbind ( 'focusin' , this . _focusSwitcher ) ;
136
184
settings . focusableEnd . unbind ( 'focusin' , this . _focusSwitcher ) ;
@@ -165,10 +213,6 @@ define([
165
213
* focusable element in modal window scope.
166
214
* If position is "start" - sets focus to last
167
215
* 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
172
216
*/
173
217
_setFocus : function ( position ) {
174
218
var settings = this . settings ,
@@ -199,6 +243,7 @@ define([
199
243
if ( settings . breakpoints ) {
200
244
_ . each ( _ . values ( settings . breakpoints ) , function ( breakpoint ) {
201
245
var conditions ;
246
+
202
247
_ . each ( _ . pairs ( breakpoint . conditions ) , function ( pair ) {
203
248
conditions = conditions ? conditions + ' and (' + pair [ 0 ] + ': ' + pair [ 1 ] + ')' :
204
249
'(' + pair [ 0 ] + ': ' + pair [ 1 ] + ')' ;
@@ -233,8 +278,7 @@ define([
233
278
var pairs ,
234
279
settings = this . settings ,
235
280
config = this . config ,
236
- startConfig = this . startConfig ,
237
- triggeredBreakpoints = 0 ;
281
+ startConfig = this . startConfig ;
238
282
239
283
if ( _ . isObject ( settings . breakpoints ) ) {
240
284
pairs = _ . pairs ( settings . breakpoints ) ;
0 commit comments