@@ -26,11 +26,9 @@ define([
26
26
zoomOutDisabled = 'fotorama__zoom-out--disabled' ,
27
27
videoContainerClass = 'fotorama-video-container' ,
28
28
hideMagnifier ,
29
- checkForVideo ,
30
29
behaveOnHover ,
31
30
dragFlag ,
32
31
endX ,
33
- zoomShown = true ,
34
32
allowZoomOut = false ,
35
33
allowZoomIn = true ;
36
34
@@ -64,9 +62,9 @@ define([
64
62
* Sets min-height and min-width for image to avoid transition bug
65
63
* @param $image - fullscreen image
66
64
*/
67
- var calculateMinSize = function ( $image ) {
65
+ function calculateMinSize ( $image ) {
68
66
69
- var minHeight ,
67
+ var minHeight ,
70
68
minWidth ,
71
69
height = $image . height ( ) ,
72
70
width = $image . width ( ) ,
@@ -118,29 +116,42 @@ define([
118
116
toggleZoomable ( $image , false ) ;
119
117
}
120
118
121
- function disableZoom ( flag ) {
122
- if ( flag ) {
119
+ /**
120
+ * Set state for zoom controls.
121
+ * If state is true, zoom controls will be visible.
122
+ * IF state is false, zoom controls will be hidden.
123
+ * @param isHide
124
+ */
125
+ function hideZoomControls ( isHide ) {
126
+ if ( isHide ) {
123
127
$ ( zoomInButtonSelector ) . addClass ( zoomInDisabled ) ;
124
128
$ ( zoomOutButtonSelector ) . addClass ( zoomOutDisabled ) ;
125
- zoomShown = false ;
126
129
} else {
127
130
$ ( zoomInButtonSelector ) . removeClass ( zoomInDisabled ) ;
128
131
$ ( zoomOutButtonSelector ) . removeClass ( zoomOutDisabled ) ;
129
- zoomShown = true ;
130
132
}
131
133
}
132
134
133
- function toggleZoomButtons ( $image ) {
135
+ /**
136
+ * Control visibility of zoom buttons.
137
+ * If image bigger than her wrapper. Zoom controls must visible.
138
+ * Zoom controls must be invisible for video content and touch devices.
139
+ * On touch devices active pinchIn/pinchOut.
140
+ * @param $image
141
+ * @param isTouchScreen - true for touch devices
142
+ * @param isVideoActiveFrame - true for active video frame
143
+ */
144
+ function toggleZoomButtons ( $image , isTouchScreen , isVideoActiveFrame ) {
134
145
var path = $image . attr ( 'src' ) ,
135
146
imgSize ;
136
147
137
- if ( path ) {
148
+ if ( path && ! isTouchScreen && ! isVideoActiveFrame ) {
138
149
imgSize = getImageSize ( path ) ;
139
150
140
151
imgSize . rh > $image . parent ( ) . height ( ) || imgSize . rw > $image . parent ( ) . width ( ) ?
141
- disableZoom ( false ) : disableZoom ( true ) ;
152
+ hideZoomControls ( false ) : hideZoomControls ( true ) ;
142
153
} else {
143
- disableZoom ( true ) ;
154
+ hideZoomControls ( true ) ;
144
155
}
145
156
}
146
157
@@ -231,7 +242,7 @@ define([
231
242
ratio ,
232
243
dimentions = { } ;
233
244
234
- if ( zoomShown && allowZoomIn ) {
245
+ if ( allowZoomIn ) {
235
246
236
247
$image = $ ( fullscreenImageSelector ) ;
237
248
imgOriginalSize = getImageSize ( $image [ 0 ] . src ) ;
@@ -263,7 +274,7 @@ define([
263
274
264
275
if ( heightResult >= imgOriginalSize . rh ) {
265
276
heightResult = imgOriginalSize . rh ;
266
- zoomHeightStep = yStep || heightResult - imageHeight ;
277
+ zoomHeightStep = yStep || heightResult - imageHeight ;
267
278
allowZoomIn = false ;
268
279
}
269
280
widthResult = heightResult * ratio ;
@@ -303,7 +314,7 @@ define([
303
314
ratio ,
304
315
fitIntoParent ;
305
316
306
- if ( zoomShown && allowZoomOut ) {
317
+ if ( allowZoomOut ) {
307
318
allowZoomIn = true ;
308
319
$image = $ ( fullscreenImageSelector ) ;
309
320
parentWidth = $image . parent ( ) . width ( ) ;
@@ -443,7 +454,7 @@ define([
443
454
/**
444
455
* Method which makes draggable picture. Also work on touch devices.
445
456
*/
446
- function magnifierFullscreen ( ) {
457
+ function magnifierFullscreen ( fotorama ) {
447
458
var isDragActive = false ,
448
459
startX ,
449
460
startY ,
@@ -549,13 +560,13 @@ define([
549
560
$image . dblclick ( dblClickHandler ) ;
550
561
551
562
if ( gallery . fullScreen ) {
552
- toggleZoomButtons ( $image ) ;
563
+ toggleZoomButtons ( $image , isTouchEnabled , checkForVideo ( fotorama . activeFrame . $stageFrame ) ) ;
553
564
}
554
565
555
- function getDimention ( event ) {
566
+ function getDimention ( event ) {
556
567
return Math . sqrt (
557
- ( event . touches [ 0 ] . clientX - event . touches [ 1 ] . clientX ) * ( event . touches [ 0 ] . clientX - event . touches [ 1 ] . clientX ) +
558
- ( event . touches [ 0 ] . clientY - event . touches [ 1 ] . clientY ) * ( event . touches [ 0 ] . clientY - event . touches [ 1 ] . clientY ) ) ;
568
+ ( event . touches [ 0 ] . clientX - event . touches [ 1 ] . clientX ) * ( event . touches [ 0 ] . clientX - event . touches [ 1 ] . clientX ) +
569
+ ( event . touches [ 0 ] . clientY - event . touches [ 1 ] . clientY ) * ( event . touches [ 0 ] . clientY - event . touches [ 1 ] . clientY ) ) ;
559
570
}
560
571
561
572
$image . off ( isTouchEnabled ? 'touchstart' : 'pointerdown mousedown MSPointerDown' ) ;
@@ -611,7 +622,7 @@ define([
611
622
612
623
if ( gallery . fullScreen && isDragActive ) {
613
624
614
- if ( zoomShown && allowZoomOut && ! $image . hasClass ( imageDraggableClass ) ) {
625
+ if ( allowZoomOut && ! $image . hasClass ( imageDraggableClass ) ) {
615
626
$image . addClass ( imageDraggableClass ) ;
616
627
}
617
628
clientX = e . clientX || e . originalEvent . clientX ;
@@ -642,39 +653,39 @@ define([
642
653
imagePosX = $ ( fullscreenImageSelector , $gallery ) . offset ( ) . left ;
643
654
imagePosY = $ ( fullscreenImageSelector , $gallery ) . offset ( ) . top ;
644
655
} ;
645
-
656
+
646
657
if ( isFullScreen && ! $focus . attr ( 'data-gallery-role' ) && e . keyCode === 9 ) {
647
658
$ ( '[data-gallery-role="fotorama__fullscreen-icon"]' ) . focus ( ) ;
648
659
e . preventDefault ( ) ;
649
660
}
650
661
651
662
if ( $focus . attr ( 'data-gallery-role' ) || ! $focus . length ) {
652
-
663
+
653
664
if ( isFullScreen ) {
654
665
imagePosX = $ ( fullscreenImageSelector , $ ( gallerySelector ) ) . offset ( ) . left ;
655
666
imagePosY = $ ( fullscreenImageSelector , $ ( gallerySelector ) ) . offset ( ) . top ;
656
667
}
657
-
668
+
658
669
if ( e . keyCode === 39 ) {
659
-
670
+
660
671
if ( isFullScreen ) {
661
672
initVars ( ) ;
662
673
shiftImage ( - step , 0 , e ) ;
663
674
} else {
664
675
$ ( gallerySelector ) . data ( 'fotorama' ) . show ( '>' ) ;
665
676
}
666
677
}
667
-
678
+
668
679
if ( e . keyCode === 38 ) {
669
-
680
+
670
681
if ( isFullScreen ) {
671
682
initVars ( ) ;
672
683
shiftImage ( 0 , step , e ) ;
673
684
}
674
685
}
675
-
686
+
676
687
if ( e . keyCode === 37 ) {
677
-
688
+
678
689
if ( isFullScreen ) {
679
690
initVars ( ) ;
680
691
shiftImage ( step , 0 , e ) ;
@@ -684,15 +695,15 @@ define([
684
695
}
685
696
686
697
if ( e . keyCode === 40 ) {
687
-
698
+
688
699
if ( isFullScreen ) {
689
700
e . preventDefault ( ) ;
690
701
initVars ( ) ;
691
702
shiftImage ( 0 , - step , e ) ;
692
703
}
693
704
}
694
705
}
695
-
706
+
696
707
if ( e . keyCode === 27 && isFullScreen ) {
697
708
$ ( gallerySelector ) . data ( 'fotorama' ) . cancelFullScreen ( ) ;
698
709
}
@@ -717,12 +728,8 @@ define([
717
728
}
718
729
} ) ;
719
730
720
- if ( zoomShown ) {
721
- toggleZoomable ( $image , true ) ;
722
- }
723
-
724
731
$ ( window ) . resize ( function ( ) {
725
- toggleZoomButtons ( $image ) ;
732
+ toggleZoomButtons ( $image , isTouchEnabled , checkForVideo ( fotorama . activeFrame . $stageFrame ) ) ;
726
733
calculateMinSize ( $image ) ;
727
734
if ( $image . hasClass ( imageZoommable ) && ! allowZoomOut ) {
728
735
resetVars ( $image ) ;
@@ -739,19 +746,22 @@ define([
739
746
} ;
740
747
741
748
/**
742
- * Check for video container.
749
+ * Check is active frame in gallery include video content.
750
+ * If true activeFrame contain video.
751
+ * @param $stageFrame - active frame in gallery
752
+ * @returns {*|Boolean }
743
753
*/
744
- checkForVideo = function ( $stageFrame ) {
754
+ function checkForVideo ( $stageFrame ) {
745
755
return $stageFrame . hasClass ( videoContainerClass ) ;
746
- } ;
756
+ }
747
757
748
758
/**
749
759
* Hides magnifier on drag and while arrow click.
750
760
*/
751
761
behaveOnHover = function ( e , initPos ) {
752
762
var pos = [ e . pageX , e . pageY ] ,
753
763
isArrow = $ ( e . target ) . data ( 'gallery-role' ) === 'arrow' ,
754
- isClick = initPos [ 0 ] === pos [ 0 ] && initPos [ 1 ] === pos [ 1 ] ,
764
+ isClick = initPos [ 0 ] === pos [ 0 ] && initPos [ 1 ] === pos [ 1 ] ,
755
765
isImg = $ ( e . target ) . parent ( ) . data ( 'active' ) ;
756
766
757
767
if ( ( isImg && ! isClick ) || isArrow ) {
@@ -852,7 +862,7 @@ define([
852
862
. on ( 'fotorama:fullscreenenter fotorama:showend' , function ( e , fotorama ) {
853
863
hideMagnifier ( ) ;
854
864
resetVars ( $ ( fullscreenImageSelector ) ) ;
855
- magnifierFullscreen ( e , fotorama ) ;
865
+ magnifierFullscreen ( fotorama ) ;
856
866
mousewheel ( e , fotorama , element ) ;
857
867
858
868
if ( $prevImage ) {
@@ -862,9 +872,9 @@ define([
862
872
} )
863
873
. on ( 'fotorama:load' , function ( e , fotorama ) {
864
874
if ( $ ( gallerySelector ) . data ( 'fotorama' ) . fullScreen ) {
865
- toggleZoomButtons ( $ ( fullscreenImageSelector ) ) ;
875
+ toggleZoomButtons ( $ ( fullscreenImageSelector ) , isTouchEnabled , checkForVideo ( fotorama . activeFrame . $stageFrame ) ) ;
866
876
}
867
- magnifierFullscreen ( ) ;
877
+ magnifierFullscreen ( fotorama ) ;
868
878
} )
869
879
. on ( 'fotorama:show' , function ( e , fotorama ) {
870
880
$prevImage = $ ( fullscreenImageSelector ) ;
@@ -873,10 +883,10 @@ define([
873
883
. on ( 'fotorama:fullscreenexit' , function ( e , fotorama ) {
874
884
resetVars ( $ ( fullscreenImageSelector ) ) ;
875
885
hideMagnifier ( ) ;
876
- disableZoom ( true ) ;
886
+ hideZoomControls ( true ) ;
877
887
} ) ;
878
888
} ) ;
879
889
880
890
return config ;
881
- }
891
+ } ;
882
892
} ) ;
0 commit comments