@@ -24,6 +24,7 @@ define([
24
24
zoomOutLoaded = 'zoom-out-loaded' ,
25
25
zoomInDisabled = 'fotorama__zoom-in--disabled' ,
26
26
zoomOutDisabled = 'fotorama__zoom-out--disabled' ,
27
+ keyboardNavigation ,
27
28
videoContainerClass = 'fotorama-video-container' ,
28
29
hideMagnifier ,
29
30
dragFlag ,
@@ -228,6 +229,36 @@ define([
228
229
$image . css ( settings ) ;
229
230
}
230
231
}
232
+ /**
233
+ * Toggles fotorama's keyboard and mouse/touch navigation.
234
+ */
235
+ function toggleStandartNavigation ( ) {
236
+ var $selectable =
237
+ $ ( 'a[href], area[href], input, select, textarea, button, iframe, object, embed, *[tabindex], *[contenteditable]' )
238
+ . not ( '[tabindex=-1], [disabled], :hidden' ) ,
239
+ fotorama = $ ( gallerySelector ) . data ( 'fotorama' ) ,
240
+ $focus = $ ( ':focus' ) ,
241
+ index ;
242
+
243
+ if ( fotorama . fullScreen ) {
244
+
245
+ $selectable . each ( function ( number ) {
246
+
247
+ if ( $ ( this ) . is ( $focus ) ) {
248
+ index = number ;
249
+ }
250
+ } ) ;
251
+
252
+ fotorama . setOptions ( {
253
+ swipe : ! allowZoomOut ,
254
+ keyboard : ! allowZoomOut
255
+ } ) ;
256
+
257
+ if ( _ . isNumber ( index ) ) {
258
+ $selectable . eq ( index ) . focus ( ) ;
259
+ }
260
+ }
261
+ } ;
231
262
232
263
function zoomIn ( e , xStep , yStep ) {
233
264
var $image ,
@@ -249,6 +280,7 @@ define([
249
280
imageHeight = $image . height ( ) ;
250
281
ratio = imageWidth / imageHeight ;
251
282
allowZoomOut = true ;
283
+ toggleStandartNavigation ( ) ;
252
284
253
285
if ( ! $image . hasClass ( imageZoommable ) ) {
254
286
toggleZoomable ( $image , true ) ;
@@ -375,6 +407,7 @@ define([
375
407
checkFullscreenImagePosition ( $image , dimentions , zoomWidthStep , zoomHeightStep ) ;
376
408
} else {
377
409
allowZoomOut = dragFlag = false ;
410
+ toggleStandartNavigation ( ) ;
378
411
fitIntoParent ( ) ;
379
412
}
380
413
}
@@ -394,6 +427,7 @@ define([
394
427
checkFullscreenImagePosition ( $image , dimentions , zoomWidthStep , zoomHeightStep ) ;
395
428
} else {
396
429
allowZoomOut = dragFlag = false ;
430
+ toggleStandartNavigation ( ) ;
397
431
fitIntoParent ( ) ;
398
432
}
399
433
}
@@ -522,12 +556,12 @@ define([
522
556
'left' : left
523
557
} ) ;
524
558
$image . css ( 'right' , '' ) ;
525
- } else if ( Math . abs ( dy ) < 1 &&
559
+ } else if ( Math . abs ( dy ) < 1 && allowZoomOut &&
526
560
! ( e . type === 'mousemove' || e . type === 'touchmove' || e . type === 'pointermove' || e . type === 'MSPointerMove' ) ) {
527
561
dx < 0 ? $ ( gallerySelector ) . data ( 'fotorama' ) . show ( '>' ) : $ ( gallerySelector ) . data ( 'fotorama' ) . show ( '<' ) ;
528
562
}
529
563
530
- if ( $image . width ( ) <= $imageContainer . width ( ) &&
564
+ if ( $image . width ( ) <= $imageContainer . width ( ) && allowZoomOut &&
531
565
( e . type === 'mousemove' || e . type === 'touchmove' || e . type === 'pointermove' || e . type === 'MSPointerMove' ) &&
532
566
Math . abs ( dx ) > Math . abs ( dy ) && Math . abs ( dx ) > swipeCondition ) {
533
567
dx < 0 ? swipeSlide ( '>' ) : swipeSlide ( '<' ) ;
@@ -640,26 +674,24 @@ define([
640
674
}
641
675
} ) ;
642
676
677
+ if ( keyboardNavigation ) {
678
+ $ ( document ) . unbind ( 'keydown' , keyboardNavigation ) ;
679
+ }
680
+
643
681
/**
644
682
* Replaces original navigations with better one
645
683
* @param e - event object
646
684
*/
647
- var keyboardNavigation = function ( e ) {
685
+ keyboardNavigation = function ( e ) {
648
686
var step = 40 ,
649
687
$focus = $ ( ':focus' ) ,
650
688
isFullScreen = $ ( gallerySelector ) . data ( 'fotorama' ) . fullScreen ,
651
689
initVars = function ( ) {
652
690
imagePosX = $ ( fullscreenImageSelector , $gallery ) . offset ( ) . left ;
653
691
imagePosY = $ ( fullscreenImageSelector , $gallery ) . offset ( ) . top ;
654
692
} ;
655
-
656
- if ( isFullScreen && ! $focus . attr ( 'data-gallery-role' ) && e . keyCode === 9 ) {
657
- $ ( '[data-gallery-role="fotorama__fullscreen-icon"]' ) . focus ( ) ;
658
- e . preventDefault ( ) ;
659
- }
660
-
661
- if ( $focus . attr ( 'data-gallery-role' ) || ! $focus . length ) {
662
-
693
+
694
+ if ( ( $focus . attr ( 'data-gallery-role' ) || ! $focus . length ) && allowZoomOut ) {
663
695
if ( isFullScreen ) {
664
696
imagePosX = $ ( fullscreenImageSelector , $ ( gallerySelector ) ) . offset ( ) . left ;
665
697
imagePosY = $ ( fullscreenImageSelector , $ ( gallerySelector ) ) . offset ( ) . top ;
@@ -670,8 +702,6 @@ define([
670
702
if ( isFullScreen ) {
671
703
initVars ( ) ;
672
704
shiftImage ( - step , 0 , e ) ;
673
- } else {
674
- $ ( gallerySelector ) . data ( 'fotorama' ) . show ( '>' ) ;
675
705
}
676
706
}
677
707
@@ -688,8 +718,6 @@ define([
688
718
if ( isFullScreen ) {
689
719
initVars ( ) ;
690
720
shiftImage ( step , 0 , e ) ;
691
- } else {
692
- $ ( gallerySelector ) . data ( 'fotorama' ) . show ( '<' ) ;
693
721
}
694
722
}
695
723
@@ -702,17 +730,16 @@ define([
702
730
}
703
731
}
704
732
}
705
-
706
- if ( e . keyCode === 27 && isFullScreen ) {
733
+
734
+ if ( e . keyCode === 27 && isFullScreen && allowZoomOut ) {
707
735
$ ( gallerySelector ) . data ( 'fotorama' ) . cancelFullScreen ( ) ;
708
736
}
709
737
} ;
710
738
711
739
/**
712
740
* @todo keyboard navigation through Fotorama Api.
713
741
*/
714
- //$(document).unbind('keydown', keyboardNavigation);
715
- //$(document).keydown(keyboardNavigation);
742
+ $ ( document ) . keydown ( keyboardNavigation ) ;
716
743
717
744
$ ( document ) . on ( isTouchEnabled ? 'touchend' : 'mouseup pointerup MSPointerUp' , function ( e ) {
718
745
@@ -866,6 +893,8 @@ define([
866
893
calculateMinSize ( $prevImage ) ;
867
894
resetVars ( $prevImage ) ;
868
895
}
896
+
897
+ toggleStandartNavigation ( ) ;
869
898
} )
870
899
. on ( 'fotorama:load' , function ( e , fotorama ) {
871
900
if ( $ ( gallerySelector ) . data ( 'fotorama' ) . fullScreen ) {
@@ -876,6 +905,7 @@ define([
876
905
. on ( 'fotorama:show' , function ( e , fotorama ) {
877
906
$prevImage = $ ( fullscreenImageSelector ) ;
878
907
hideMagnifier ( ) ;
908
+ resetVars ( $ ( fullscreenImageSelector ) ) ;
879
909
} )
880
910
. on ( 'fotorama:fullscreenexit' , function ( e , fotorama ) {
881
911
resetVars ( $ ( fullscreenImageSelector ) ) ;
0 commit comments