Skip to content

Commit 6b38176

Browse files
authored
Merge pull request #82 from magento-lynx/jquery-upgrade
[LYNX] Jquery upgrade compatibility changes
2 parents f9bacbf + 34b7550 commit 6b38176

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/block-chooser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ define([
8484
this.errorMessage(this.messages.UNKOWN_ERROR);
8585

8686
return;
87-
} else if ($.isArray(response)) {
87+
} else if (Array.isArray(response)) {
8888
this.meta({});
8989
this.errorMessage(this.messages.UNKNOWN_SELECTION);
9090

app/code/Magento/PageBuilder/view/base/web/js/widget/show-on-hover.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ define(['jquery'], function ($) {
1616
var overlayEl = $(element).find('.pagebuilder-overlay'),
1717
overlayColor = overlayEl.attr('data-overlay-color');
1818

19-
$(element).hover(
20-
function () {
21-
overlayEl.css('background-color', overlayColor);
22-
},
23-
function () {
24-
overlayEl.css('background-color', 'transparent');
25-
}
26-
);
19+
$(element).on('mouseenter', function () {
20+
overlayEl.css('background-color', overlayColor);
21+
});
22+
23+
$(element).on('mouseleave', function () {
24+
overlayEl.css('background-color', 'transparent');
25+
});
2726
});
2827
}
2928

@@ -37,19 +36,19 @@ define(['jquery'], function ($) {
3736
$elements.each(function (index, element) {
3837
var buttonEl = $(element).find(buttonClass);
3938

40-
$(element).hover(
41-
function () {
42-
buttonEl.css({
43-
'opacity': '1',
44-
'visibility': 'visible'
45-
});
46-
}, function () {
47-
buttonEl.css({
48-
'opacity': '0',
49-
'visibility': 'hidden'
50-
});
51-
}
52-
);
39+
$(element).on('mouseenter', function () {
40+
buttonEl.css({
41+
'opacity': '1',
42+
'visibility': 'visible'
43+
});
44+
});
45+
46+
$(element).on('mouseleave', function () {
47+
buttonEl.css({
48+
'opacity': '0',
49+
'visibility': 'hidden'
50+
});
51+
});
5352
});
5453
}
5554

dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/frontend/web/js/widget/show-on-hover.test.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ define([
1717
});
1818

1919
describe('Magento_PageBuilder/js/widget/show-on-hover', function () {
20-
it('Should call hover twice if both data attributes match config value', function () {
20+
it('Should call "on" four times if both data attributes match config value', function () {
2121
var config = {
2222
dataRole: 'thing',
2323
buttonSelector: '.button-selector',
@@ -37,14 +37,16 @@ define([
3737

3838
el.appendTo('body');
3939

40-
spyOn($.fn, 'hover');
40+
spyOn($.fn, 'on');
4141

4242
showOnHoverInitializerWidget(config);
4343

44-
expect($.fn.hover).toHaveBeenCalledTimes(2);
44+
expect($.fn.on).toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
45+
expect($.fn.on).toHaveBeenCalledWith('mouseleave', jasmine.any(Function));
46+
expect($.fn.on).toHaveBeenCalledTimes(4);
4547
});
4648

47-
it('Should call hover zero times if no data attributes match config value', function () {
49+
it('Should call "on" zero times if no data attributes match config value', function () {
4850
var config = {
4951
dataRole: 'thing',
5052
buttonSelector: '.button-selector',
@@ -64,14 +66,15 @@ define([
6466

6567
el.appendTo('body');
6668

67-
spyOn($.fn, 'hover');
69+
spyOn($.fn, 'on');
6870

6971
showOnHoverInitializerWidget(config);
7072

71-
expect($.fn.hover).not.toHaveBeenCalled();
73+
expect($.fn.on).not.toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
74+
expect($.fn.on).not.toHaveBeenCalledWith('mouseleave', jasmine.any(Function));
7275
});
7376

74-
it('Should call hover one time if only data-show-overlay matches config value', function () {
77+
it('Should call "on" twice if only data-show-overlay matches config value', function () {
7578
var config = {
7679
dataRole: 'thing',
7780
buttonSelector: '.button-selector',
@@ -91,14 +94,16 @@ define([
9194

9295
el.appendTo('body');
9396

94-
spyOn($.fn, 'hover');
97+
spyOn($.fn, 'on');
9598

9699
showOnHoverInitializerWidget(config);
97100

98-
expect($.fn.hover).toHaveBeenCalledTimes(1);
101+
expect($.fn.on).toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
102+
expect($.fn.on).toHaveBeenCalledWith('mouseleave', jasmine.any(Function));
103+
expect($.fn.on).toHaveBeenCalledTimes(2);
99104
});
100105

101-
it('Should call hover one time if only data-show-button matches config value', function () {
106+
it('Should call "on" twice if only data-show-button matches config value', function () {
102107
var config = {
103108
dataRole: 'thing',
104109
buttonSelector: '.button-selector',
@@ -118,14 +123,16 @@ define([
118123

119124
el.appendTo('body');
120125

121-
spyOn($.fn, 'hover');
126+
spyOn($.fn, 'on');
122127

123128
showOnHoverInitializerWidget(config);
124129

125-
expect($.fn.hover).toHaveBeenCalledTimes(1);
130+
expect($.fn.on).toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
131+
expect($.fn.on).toHaveBeenCalledWith('mouseleave', jasmine.any(Function));
132+
expect($.fn.on).toHaveBeenCalledTimes(2);
126133
});
127134

128-
it('Should call hover zero times if data-content-type does not match config value', function () {
135+
it('Should call "on" zero times if data-content-type does not match config value', function () {
129136
var config = {
130137
dataRole: 'thing2',
131138
buttonSelector: '.button-selector',
@@ -145,11 +152,12 @@ define([
145152

146153
el.appendTo('body');
147154

148-
spyOn($.fn, 'hover');
155+
spyOn($.fn, 'on');
149156

150157
showOnHoverInitializerWidget(config);
151158

152-
expect($.fn.hover).not.toHaveBeenCalled();
159+
expect($.fn.on).not.toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
160+
expect($.fn.on).not.toHaveBeenCalledWith('mouseleave', jasmine.any(Function));
153161
});
154162
});
155163
});

0 commit comments

Comments
 (0)