Skip to content

Commit fb48c59

Browse files
committed
MC-3934: Slide/Banner Overlay & Button Do Not Show On Storefront When Set To On Hover
Support target _blank
1 parent e455201 commit fb48c59

File tree

2 files changed

+60
-11
lines changed

2 files changed

+60
-11
lines changed

app/code/Magento/PageBuilder/view/base/web/js/widget/bind-click-to-data-link-element.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ define(['jquery'], function ($) {
3131
return;
3232
}
3333

34-
bindClickWidget.redirectTo($linkElement.attr('href'));
34+
bindClickWidget.redirectTo(
35+
$linkElement.attr('href'),
36+
$linkElement.attr('target')
37+
);
3538
});
3639
});
3740
}
3841

3942
/**
40-
* Navigate to href in browser
43+
* Navigate to href in browser. Open in new window if target is '_blank'
4144
* @param {String} href
45+
* @param {String} target
4246
*/
43-
bindClickWidget.redirectTo = function (href) {
44-
window.location.href = href;
47+
bindClickWidget.redirectTo = function (href, target) {
48+
if (target === '_blank') {
49+
window.open(href, target);
50+
} else {
51+
window.location.href = href;
52+
}
4553
};
4654

4755
return bindClickWidget;

dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/frontend/web/js/widget/bind-click-to-data-link-element.test.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ define([
88
], function (bindClickToLinkInitializerWidget, $) {
99
'use strict';
1010

11-
var $el;
11+
var $el,
12+
originalRedirectTo = bindClickToLinkInitializerWidget.redirectTo;
1213

1314
afterEach(function () {
1415
if ($el !== undefined) {
@@ -19,9 +20,11 @@ define([
1920
describe('Magento_PageBuilder/js/widget/bind-click-to-data-link-element', function () {
2021
it('Should not navigate away from page if it is missing href attribute', function () {
2122
spyOn(bindClickToLinkInitializerWidget, 'redirectTo');
23+
spyOn(window, 'open');
24+
2225
$el = $(
2326
'<div data-role="content-type">' +
24-
'<div data-link-type="link" href="">' +
27+
'<div data-link-type="link" href="" target>' +
2528
'<span class="span-outside-inner-anchor">Hello world</span>' +
2629
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
2730
'</div>' +
@@ -35,13 +38,16 @@ define([
3538
$el.find('.span-outside-inner-anchor').click();
3639

3740
expect(bindClickToLinkInitializerWidget.redirectTo).not.toHaveBeenCalled();
41+
expect(window.open).not.toHaveBeenCalled();
3842
});
3943

4044
it('Should not navigate away from page if href is javascript:void(0)', function () {
4145
spyOn(bindClickToLinkInitializerWidget, 'redirectTo');
46+
spyOn(window, 'open');
47+
4248
$el = $(
4349
'<div data-role="content-type">' +
44-
'<div data-link-type="link" href="javascript:void(0)">' +
50+
'<div data-link-type="link" href="javascript:void(0)" target>' +
4551
'<span class="span-outside-inner-anchor">Hello world</span>' +
4652
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
4753
'</div>' +
@@ -55,13 +61,16 @@ define([
5561
$el.find('.span-outside-inner-anchor').click();
5662

5763
expect(bindClickToLinkInitializerWidget.redirectTo).not.toHaveBeenCalled();
64+
expect(window.open).not.toHaveBeenCalled();
5865
});
5966

6067
it('Should not navigate away from page if it is missing data-link-type attribute', function () {
6168
spyOn(bindClickToLinkInitializerWidget, 'redirectTo');
69+
spyOn(window, 'open');
70+
6271
$el = $(
6372
'<div data-role="content-type">' +
64-
'<div href="https://adobe.com">' +
73+
'<div href="https://adobe.com" target>' +
6574
'<span class="span-outside-inner-anchor">Hello world</span>' +
6675
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
6776
'</div>' +
@@ -75,14 +84,16 @@ define([
7584
$el.find('.span-outside-inner-anchor').click();
7685

7786
expect(bindClickToLinkInitializerWidget.redirectTo).not.toHaveBeenCalled();
87+
expect(window.open).not.toHaveBeenCalled();
7888
});
7989

8090
it('Should not navigate to an simulated anchor\'s href if clicked inside of nested anchor', function () {
8191
spyOn(bindClickToLinkInitializerWidget, 'redirectTo');
92+
spyOn(window, 'open');
8293

8394
$el = $(
8495
'<div data-role="content-type">' +
85-
'<div data-link-type="link" href="https://adobe.com">' +
96+
'<div data-link-type="link" href="https://adobe.com" target>' +
8697
'<span class="span-outside-inner-anchor">Hello world</span>' +
8798
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
8899
'</div>' +
@@ -96,14 +107,16 @@ define([
96107
$el.find('.inner-anchor').click();
97108

98109
expect(bindClickToLinkInitializerWidget.redirectTo).not.toHaveBeenCalled();
110+
expect(window.open).not.toHaveBeenCalled();
99111
});
100112

101113
it('Should navigate to an simulated anchor\'s href if clicked outside of nested anchor', function () {
102114
spyOn(bindClickToLinkInitializerWidget, 'redirectTo');
115+
spyOn(window, 'open');
103116

104117
$el = $(
105118
'<div data-role="content-type">' +
106-
'<div data-link-type="link" href="https://adobe.com">' +
119+
'<div data-link-type="link" href="https://adobe.com" target>' +
107120
'<span class="span-outside-inner-anchor">Hello world</span>' +
108121
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
109122
'</div>' +
@@ -116,7 +129,35 @@ define([
116129

117130
$el.find('.span-outside-inner-anchor').click();
118131

119-
expect(bindClickToLinkInitializerWidget.redirectTo).toHaveBeenCalledWith('https://adobe.com');
132+
expect(bindClickToLinkInitializerWidget.redirectTo).toHaveBeenCalledWith('https://adobe.com', '');
133+
134+
originalRedirectTo('https://adobe.com', '');
135+
expect(window.open).not.toHaveBeenCalled();
136+
});
137+
138+
it('Should call window.open if target is _blank', function () {
139+
spyOn(window, 'open');
140+
spyOn(bindClickToLinkInitializerWidget, 'redirectTo');
141+
142+
$el = $(
143+
'<div data-role="content-type">' +
144+
'<div data-link-type="link" href="https://adobe.com" target="_blank">' +
145+
'<span class="span-outside-inner-anchor">Hello world</span>' +
146+
'<a class="inner-anchor" href="https://something.com"><span>Something</span></a>' +
147+
'</div>' +
148+
'</div>'
149+
);
150+
151+
$el.appendTo('body');
152+
153+
bindClickToLinkInitializerWidget(null, $el);
154+
155+
$el.find('.span-outside-inner-anchor').click();
156+
157+
expect(bindClickToLinkInitializerWidget.redirectTo).toHaveBeenCalledWith('https://adobe.com', '_blank');
158+
159+
originalRedirectTo('https://adobe.com', '_blank');
160+
expect(window.open).toHaveBeenCalledWith('https://adobe.com', '_blank');
120161
});
121162
});
122163
});

0 commit comments

Comments
 (0)