Skip to content

Commit 1b07b00

Browse files
committed
ACP2E-4231: Fotorama can open Mini Cart on Image Viewer close action
1 parent 7af41cb commit 1b07b00

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Copyright 2025 Adobe
3+
* All Rights Reserved.
4+
*/
5+
/**
6+
* Verifies fotorama stopEvent behavior on mobile vs desktop interactions.
7+
*/
8+
define([
9+
'jquery',
10+
'text!/lib/web/fotorama/fotorama.js'
11+
], function ($, fotoramaSource) {
12+
'use strict';
13+
14+
describe('lib/web/fotorama/fotorama.js stopEvent', function () {
15+
var originalMatchMedia, originalModernizr, stopEventFn;
16+
17+
function extractStopEvent(source) {
18+
var start = source.indexOf('function stopEvent');
19+
if (start === -1) {
20+
return undefined;
21+
}
22+
var braceStart = source.indexOf('{', start);
23+
var depth = 0, i = braceStart, end = -1;
24+
for (; i < source.length; i++) {
25+
var ch = source[i];
26+
if (ch === '{') {
27+
depth++;
28+
} else if (ch === '}') {
29+
depth--;
30+
if (depth === 0) {
31+
end = i + 1;
32+
break;
33+
}
34+
}
35+
}
36+
if (end === -1) {
37+
return undefined;
38+
}
39+
// eslint-disable-next-line no-new-func
40+
return (new Function('return (' + source.slice(start, end) + ');'))();
41+
}
42+
43+
beforeAll(function () {
44+
originalMatchMedia = window.matchMedia;
45+
originalModernizr = window.Modernizr;
46+
});
47+
48+
afterAll(function () {
49+
window.matchMedia = originalMatchMedia;
50+
window.Modernizr = originalModernizr;
51+
});
52+
53+
beforeEach(function () {
54+
// Ensure Modernizr exists; the function references it
55+
window.Modernizr = window.Modernizr || { touch: false };
56+
stopEventFn = extractStopEvent(fotoramaSource);
57+
});
58+
59+
function mockEvent(type) {
60+
return {
61+
type: type,
62+
preventDefault: jasmine.createSpy('preventDefault'),
63+
stopPropagation: jasmine.createSpy('stopPropagation'),
64+
returnValue: true
65+
};
66+
}
67+
68+
it('prevents default and stops propagation on mobile touchend', function () {
69+
window.matchMedia = function () { return { matches: true }; };
70+
var e = mockEvent('touchend');
71+
stopEventFn(e);
72+
expect(e.preventDefault).toHaveBeenCalled();
73+
expect(e.stopPropagation).toHaveBeenCalled();
74+
});
75+
76+
it('prevents default on desktop click when Modernizr.touch is false', function () {
77+
window.matchMedia = function () { return { matches: false }; };
78+
window.Modernizr.touch = false;
79+
var e = mockEvent('click');
80+
stopEventFn(e);
81+
expect(e.preventDefault).toHaveBeenCalled();
82+
});
83+
84+
it('does not prevent default on desktop click when Modernizr.touch is true', function () {
85+
window.matchMedia = function () { return { matches: false }; };
86+
window.Modernizr.touch = true;
87+
var e = mockEvent('click');
88+
stopEventFn(e);
89+
expect(e.preventDefault).not.toHaveBeenCalled();
90+
});
91+
92+
it('stops propagation when second argument is true', function () {
93+
window.matchMedia = function () { return { matches: false }; };
94+
window.Modernizr.touch = false;
95+
var e = mockEvent('click');
96+
stopEventFn(e, true);
97+
expect(e.stopPropagation).toHaveBeenCalled();
98+
});
99+
});
100+
});
101+
102+

lib/web/fotorama/fotorama.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright 2015 Adobe
3+
* All Rights Reserved.
4+
*/
15
/*!
26
* Fotorama 4.6.4 | http://fotorama.io/license/
37
*/
@@ -1219,6 +1223,13 @@ fotoramaVersion = '4.6.4';
12191223
}
12201224

12211225
function stopEvent(e, stopPropagation) {
1226+
const isMobile = window.matchMedia('(pointer:coarse)').matches;
1227+
1228+
if (isMobile && e.type === 'touchend') {
1229+
e.preventDefault && e.preventDefault();
1230+
e.stopPropagation && e.stopPropagation();
1231+
return;
1232+
}
12221233
if (!Modernizr.touch) {
12231234
e.preventDefault ? e.preventDefault() : (e.returnValue = false);
12241235
}

0 commit comments

Comments
 (0)