Skip to content

Commit 757efb0

Browse files
JS-497: Fast screen resize in fullscreen mode breaks image size
1 parent fb424ad commit 757efb0

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
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: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ define([
639639
e.preventDefault();
640640
pinchDimention = getDimention(e.originalEvent);
641641
isDragActive = false;
642+
642643
if ($image.hasClass(imageDraggableClass)) {
643644
$image.removeClass(imageDraggableClass);
644645
}
@@ -670,6 +671,7 @@ define([
670671
if (e && e.originalEvent.touches && e.originalEvent.touches.length >= 2) {
671672
e.preventDefault();
672673
var currentDimention = getDimention(e.originalEvent);
674+
673675
if ($image.hasClass(imageDraggableClass)) {
674676
$image.removeClass(imageDraggableClass);
675677
}
@@ -726,7 +728,7 @@ define([
726728
imagePosX = $(fullscreenImageSelector, $gallery).offset().left;
727729
imagePosY = $(fullscreenImageSelector, $gallery).offset().top;
728730
};
729-
731+
730732
if (($focus.attr('data-gallery-role') || !$focus.length) && allowZoomOut) {
731733
if (isFullScreen) {
732734
imagePosX = $(fullscreenImageSelector, $(gallerySelector)).offset().left;
@@ -766,7 +768,7 @@ define([
766768
}
767769
}
768770
}
769-
771+
770772
if (e.keyCode === 27 && isFullScreen && allowZoomOut) {
771773
$(gallerySelector).data('fotorama').cancelFullScreen();
772774
}
@@ -781,7 +783,7 @@ define([
781783

782784
if (gallery.fullScreen) {
783785

784-
if ($image.offset() && ($image.width() > $imageContainer.width())) {
786+
if ($image.offset() && $image.width() > $imageContainer.width()) {
785787
endX = $image.offset().left;
786788
}
787789

@@ -791,9 +793,15 @@ define([
791793
});
792794

793795
$(window).resize(function () {
796+
var imageSize = getImageSize($(fullscreenImageSelector)[0].src),
797+
isImageSmall =
798+
$(fullscreenImageSelector).parent().width() >= imageSize.rw &&
799+
$(fullscreenImageSelector).parent().height() >= imageSize.rh;
800+
794801
toggleZoomButtons($image, isTouchEnabled, checkForVideo(fotorama.activeFrame.$stageFrame));
795802
calculateMinSize($image);
796-
if ($image.hasClass(imageZoommable) && !allowZoomOut) {
803+
804+
if ($image.hasClass(imageZoommable) && !allowZoomOut || isImageSmall) {
797805
resetVars($image);
798806
}
799807
});
@@ -826,7 +834,7 @@ define([
826834
isClick = initPos[0] === pos[0] && initPos[1] === pos[1],
827835
isImg = $(e.target).parent().data('active');
828836

829-
if (isArrow || (isImg && !isClick)) {
837+
if (isArrow || isImg && !isClick) {
830838
hideMagnifier();
831839
}
832840
}
@@ -866,8 +874,10 @@ define([
866874

867875
$(element).on('fotorama:load fotorama:showend fotorama:fullscreenexit fotorama:ready', function (e, fotorama) {
868876
var $activeStageFrame = $(gallerySelector).data('fotorama').activeFrame.$stageFrame;
877+
869878
if (!$activeStageFrame.find(magnifierZoomSelector).length) {
870879
hideMagnifier();
880+
871881
if (config.magnifierOpts) {
872882
config.magnifierOpts.large = $(gallerySelector).data('fotorama').activeFrame.img;
873883
config.magnifierOpts.full = fotorama.data[fotorama.activeIndex].original;
@@ -951,7 +961,8 @@ define([
951961
})
952962
.on('fotorama:load', function (e, fotorama) {
953963
if ($(gallerySelector).data('fotorama').fullScreen) {
954-
toggleZoomButtons($(fullscreenImageSelector), isTouchEnabled, checkForVideo(fotorama.activeFrame.$stageFrame));
964+
toggleZoomButtons($(fullscreenImageSelector), isTouchEnabled,
965+
checkForVideo(fotorama.activeFrame.$stageFrame));
955966
}
956967
magnifierFullscreen(fotorama);
957968
})

0 commit comments

Comments
 (0)