Skip to content

Commit de0b2f9

Browse files
committed
Merge branch 'ACP2E-3029' of https://github.com/adobe-commerce-tier-4/magento2ce into TIer4-PR-07-22-2024
2 parents 06cfb37 + c741cba commit de0b2f9

File tree

2 files changed

+100
-12
lines changed

2 files changed

+100
-12
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*************************
2+
*
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* ***********************
7+
*/
8+
9+
/*eslint max-nested-callbacks: 0*/
10+
define(['magnifier/magnify', 'mage/gallery/gallery', 'jquery'], function (Magnify, Gallery, $) {
11+
'use strict';
12+
13+
describe('magnifier/magnify', function () {
14+
var gallery, options;
15+
16+
beforeEach(function () {
17+
options = {
18+
options: {
19+
'nav':'thumbs','loop':true,'keyboard':true,'arrows':true,'allowfullscreen':true,
20+
'showCaption':false,'width':700,'thumbwidth':88,'thumbheight':110,'height':700,
21+
'transitionduration':500,'transition':'slide','navarrows':true,'navtype':'slides',
22+
'navdir':'horizontal','whiteBorders':1
23+
},
24+
fullscreen: {
25+
'nav':'thumbs','loop':true,'navdir':'horizontal','navarrows':false,'navtype':'slides',
26+
'arrows':true,'showCaption':false,'transitionduration':500,'transition':'slide','whiteBorders':1
27+
},
28+
breakpoints: {'mobile':{'conditions':{'max-width':'767px'},'options':{'options':{'nav':'dots'}}}},
29+
data: [
30+
{
31+
'thumb':'dev/tests/acceptance/tests/_data/adobe-base.jpg',
32+
'img':'dev/tests/acceptance/tests/_data/adobe-base.jpg',
33+
'full':'dev/tests/acceptance/tests/_data/adobe-base.jpg',
34+
'caption':'simple1','position':'0','isMain':false,'type':'image','videoUrl':null
35+
}
36+
],
37+
magnifierOpts: {
38+
'fullscreenzoom':'20',
39+
'top':'',
40+
'left':'',
41+
'width':'',
42+
'height':'',
43+
'eventType':'hover',
44+
'enabled':false,
45+
'mode':'outside'
46+
}
47+
};
48+
});
49+
50+
describe('test magnifierFullscreen method', function () {
51+
it('Check if the current image has event handlers set for tap and double tap', function () {
52+
let pageWrapperDiv, productMediaDiv, mainDiv, img, activeImage, imageEvents;
53+
54+
pageWrapperDiv = document.createElement('div');
55+
pageWrapperDiv.className = 'page-wrapper';
56+
57+
productMediaDiv = document.createElement('div');
58+
productMediaDiv.className = 'product media';
59+
60+
mainDiv = document.createElement('div');
61+
mainDiv.id = 'gallery_placeholder';
62+
mainDiv.className = 'gallery-placeholder _block-content-loading';
63+
mainDiv.setAttribute('data-gallery-role', 'gallery-placeholder');
64+
65+
img = document.createElement('img');
66+
img.alt = 'main product photo';
67+
img.id = 'main_product_photo';
68+
img.className = 'gallery-placeholder__image';
69+
img.src = 'dev/tests/acceptance/tests/_data/adobe-base.jpg';
70+
71+
mainDiv.appendChild(img);
72+
pageWrapperDiv.appendChild(productMediaDiv);
73+
productMediaDiv.appendChild(mainDiv);
74+
document.body.appendChild(pageWrapperDiv);
75+
76+
new Magnify(options, $('#gallery_placeholder'));
77+
gallery = new Gallery(options, $('#gallery_placeholder'));
78+
79+
activeImage = document.createElement('img');
80+
activeImage.className = 'fotorama__img--full';
81+
$('[data-gallery-role="stage-shaft"] [data-active="true"]').append(activeImage);
82+
83+
gallery.openFullScreen();
84+
85+
imageEvents = $._data($('.fotorama__img--full')[0], 'events');
86+
expect(imageEvents).toBeInstanceOf(Object);
87+
expect(Object.getOwnPropertyNames(imageEvents)).toContain('touchend');
88+
});
89+
});
90+
});
91+
});

lib/web/magnifier/magnify.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ define([
274274
function toggleStandartNavigation() {
275275
var $selectable =
276276
$('a[href], area[href], input, select, textarea, button, iframe, object, embed, *[tabindex], *[contenteditable]')
277-
.not('[tabindex=-1], [disabled], :hidden'),
277+
.not('[tabindex=-1], [disabled], :hidden'),
278278
fotorama = $(gallerySelector).data('fotorama'),
279279
$focus = $(':focus'),
280280
index;
@@ -520,6 +520,7 @@ define([
520520
* Method which makes draggable picture. Also work on touch devices.
521521
*/
522522
function magnifierFullscreen(fotorama) {
523+
tapFlag = 0;
523524
var isDragActive = false,
524525
startX,
525526
startY,
@@ -613,6 +614,9 @@ define([
613614
* @param e - event object
614615
*/
615616
function dblClickHandler(e) {
617+
if ($image.length === 0) {
618+
$image = $(fullscreenImageSelector, $gallery);
619+
}
616620
var imgOriginalSize = getImageSize($image[0]),
617621
proportions;
618622

@@ -632,25 +636,18 @@ define([
632636
}
633637

634638
function detectDoubleTap(e) {
635-
var now = new Date().getTime(),
639+
let now = new Date().getTime(),
636640
timesince = now - tapFlag;
637641

638-
if (timesince < 400 && timesince > 0) {
642+
if (timesince > 20 && (isTouchEnabled && timesince < 400) || (!isTouchEnabled && timesince < 2000)) {
639643
transitionActive = false;
640-
tapFlag = 0;
641644
dblClickHandler(e);
642-
} else {
643-
tapFlag = new Date().getTime();
644645
}
646+
tapFlag = now;
645647
}
646648

647649
if (isTouchEnabled) {
648-
$image.off('tap');
649-
$image.on('tap', function (e) {
650-
if (e.originalEvent.originalEvent.touches.length === 0) {
651-
detectDoubleTap(e);
652-
}
653-
});
650+
$image.on('touchend', detectDoubleTap);
654651
} else {
655652
$image.off('dblclick');
656653
$image.on('dblclick', dblClickHandler);

0 commit comments

Comments
 (0)