Skip to content

Commit 649e007

Browse files
author
Volodymyr Zaets
committed
MAGETWO-50665 - Processing pull request sky team
- Merge remote-tracking branch 'epam/JS-493' into JS-493 - Conflicts: lib/web/magnifier/magnify.js
2 parents a7a7dbf + 046db58 commit 649e007

File tree

2 files changed

+61
-31
lines changed

2 files changed

+61
-31
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<?php if ($block->getVar("gallery/fullscreen/loop")): ?>
8888
"loop": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/loop"); ?>,
8989
<?php endif; ?>
90-
"navdir": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/navdir"); ?>",
90+
"navdir": "<?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/navdir"); ?>",
9191
<?php if ($block->getVar("gallery/transition/navarrows")): ?>
9292
"navarrows": <?php /* @escapeNotVerified */ echo $block->getVar("gallery/fullscreen/navarrows"); ?>,
9393
<?php endif; ?>

lib/web/magnifier/magnify.js

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ define([
3030
dragFlag,
3131
endX,
3232
transitionActive = false,
33-
tapedTwice = false,
33+
tapFlag = 0,
3434
allowZoomOut = false,
3535
allowZoomIn = true;
3636

@@ -504,6 +504,7 @@ define([
504504
$imageContainer = $('[data-gallery-role="stage-shaft"] [data-active="true"]'),
505505
gallery = $gallery.data('fotorama'),
506506
pinchDimention;
507+
507508
swipeSlide = _.throttle(function (direction) {
508509
$(gallerySelector).data('fotorama').show(direction);
509510
}, 500, {
@@ -579,6 +580,10 @@ define([
579580
var imgOriginalSize = getImageSize($image[0].src),
580581
proportions;
581582

583+
if (imgOriginalSize.rh < $image.parent().height() && imgOriginalSize.rw < $image.parent().width()) {
584+
return;
585+
}
586+
582587
proportions = imgOriginalSize.rw / imgOriginalSize.rh;
583588

584589
if (allowZoomIn) {
@@ -592,8 +597,30 @@ define([
592597
}
593598
}
594599

595-
$image.unbind('dblclick');
596-
$image.dblclick(dblClickHandler);
600+
function detectDoubleTap(e) {
601+
var now = new Date().getTime(),
602+
timesince = now - tapFlag;
603+
604+
if (timesince < 400 && timesince > 0) {
605+
transitionActive = false;
606+
tapFlag = 0;
607+
dblClickHandler(e);
608+
} else {
609+
tapFlag = new Date().getTime();
610+
}
611+
}
612+
613+
if (isTouchEnabled) {
614+
$image.off('tap');
615+
$image.on('tap', function (e) {
616+
if (e.originalEvent.originalEvent.touches.length === 0) {
617+
detectDoubleTap(e);
618+
}
619+
});
620+
} else {
621+
$image.unbind('dblclick');
622+
$image.dblclick(dblClickHandler);
623+
}
597624

598625
if (gallery.fullScreen) {
599626
toggleZoomButtons($image, isTouchEnabled, checkForVideo(fotorama.activeFrame.$stageFrame));
@@ -611,6 +638,7 @@ define([
611638
e.preventDefault();
612639
pinchDimention = getDimention(e.originalEvent);
613640
isDragActive = false;
641+
614642
if ($image.hasClass(imageDraggableClass)) {
615643
$image.removeClass(imageDraggableClass);
616644
}
@@ -642,6 +670,7 @@ define([
642670
if (e && e.originalEvent.touches && e.originalEvent.touches.length >= 2) {
643671
e.preventDefault();
644672
var currentDimention = getDimention(e.originalEvent);
673+
645674
if ($image.hasClass(imageDraggableClass)) {
646675
$image.removeClass(imageDraggableClass);
647676
}
@@ -698,7 +727,7 @@ define([
698727
imagePosX = $(fullscreenImageSelector, $gallery).offset().left;
699728
imagePosY = $(fullscreenImageSelector, $gallery).offset().top;
700729
};
701-
730+
702731
if (($focus.attr('data-gallery-role') || !$focus.length) && allowZoomOut) {
703732
if (isFullScreen) {
704733
imagePosX = $(fullscreenImageSelector, $(gallerySelector)).offset().left;
@@ -738,7 +767,7 @@ define([
738767
}
739768
}
740769
}
741-
770+
742771
if (e.keyCode === 27 && isFullScreen && allowZoomOut) {
743772
$(gallerySelector).data('fotorama').cancelFullScreen();
744773
}
@@ -752,7 +781,7 @@ define([
752781
$(document).on(isTouchEnabled ? 'touchend' : 'mouseup pointerup MSPointerUp', function (e) {
753782
if (gallery.fullScreen) {
754783

755-
if ($image.offset() && ($image.width() > $imageContainer.width())) {
784+
if ($image.offset() && $image.width() > $imageContainer.width()) {
756785
endX = $image.offset().left;
757786
}
758787

@@ -761,29 +790,22 @@ define([
761790
}
762791
});
763792

764-
isTouchEnabled && $image.off('touchend');
765-
isTouchEnabled && $image.on('touchend', function (e) {
766-
if (e.originalEvent.touches.length === 0) {
767-
if (!tapedTwice) {
768-
tapedTwice = true;
769-
setTimeout(function () {
770-
tapedTwice = false;
771-
}, 300);
772-
773-
return;
774-
}
775-
toggleZoomable($image, allowZoomOut);
776-
dblClickHandler(e);
777-
}
778-
});
779-
780-
781793
$(window).resize(function () {
794+
var imageSize = getImageSize($(fullscreenImageSelector)[0].src),
795+
isImageSmall =
796+
$(fullscreenImageSelector).parent().width() >= imageSize.rw &&
797+
$(fullscreenImageSelector).parent().height() >= imageSize.rh;
798+
782799
toggleZoomButtons($image, isTouchEnabled, checkForVideo(fotorama.activeFrame.$stageFrame));
783800
calculateMinSize($image);
784-
if ($image.hasClass(imageZoommable) && !allowZoomOut) {
801+
802+
if ($image.hasClass(imageZoommable) && !allowZoomOut || isImageSmall) {
785803
resetVars($image);
786804
}
805+
806+
if (!isImageSmall) {
807+
toggleStandartNavigation();
808+
}
787809
});
788810
}
789811

@@ -814,7 +836,7 @@ define([
814836
isClick = initPos[0] === pos[0] && initPos[1] === pos[1],
815837
isImg = $(e.target).parent().data('active');
816838

817-
if (isArrow || (isImg && !isClick)) {
839+
if (isArrow || isImg && !isClick) {
818840
hideMagnifier();
819841
}
820842
}
@@ -854,8 +876,10 @@ define([
854876

855877
$(element).on('fotorama:load fotorama:showend fotorama:fullscreenexit fotorama:ready', function (e, fotorama) {
856878
var $activeStageFrame = $(gallerySelector).data('fotorama').activeFrame.$stageFrame;
879+
857880
if (!$activeStageFrame.find(magnifierZoomSelector).length) {
858881
hideMagnifier();
882+
859883
if (config.magnifierOpts) {
860884
config.magnifierOpts.large = $(gallerySelector).data('fotorama').activeFrame.img;
861885
config.magnifierOpts.full = fotorama.data[fotorama.activeIndex].original;
@@ -920,27 +944,33 @@ define([
920944
})
921945
.on('fotorama:fullscreenenter fotorama:showend', function (e, fotorama) {
922946
hideMagnifier();
923-
!tapedTwice && resetVars($(fullscreenImageSelector));
947+
948+
if (!$(fullscreenImageSelector).is($prevImage)) {
949+
resetVars($(fullscreenImageSelector));
950+
}
924951
magnifierFullscreen(fotorama);
925952
mousewheel(e, fotorama, element);
926953

927954
if ($prevImage) {
928955
calculateMinSize($prevImage);
929-
resetVars($prevImage);
956+
957+
if (!$(fullscreenImageSelector).is($prevImage)) {
958+
resetVars($prevImage);
959+
}
930960
}
931961

932962
toggleStandartNavigation();
933963
})
934964
.on('fotorama:load', function (e, fotorama) {
935965
if ($(gallerySelector).data('fotorama').fullScreen) {
936-
toggleZoomButtons($(fullscreenImageSelector), isTouchEnabled, checkForVideo(fotorama.activeFrame.$stageFrame));
966+
toggleZoomButtons($(fullscreenImageSelector), isTouchEnabled,
967+
checkForVideo(fotorama.activeFrame.$stageFrame));
937968
}
938969
magnifierFullscreen(fotorama);
939970
})
940971
.on('fotorama:show', function (e, fotorama) {
941-
$prevImage = $(fullscreenImageSelector);
972+
$prevImage = _.clone($(fullscreenImageSelector));
942973
hideMagnifier();
943-
!tapedTwice && resetVars($(fullscreenImageSelector));
944974
})
945975
.on('fotorama:fullscreenexit', function (e, fotorama) {
946976
resetVars($(fullscreenImageSelector));

0 commit comments

Comments
 (0)