Skip to content

Commit

Permalink
MC-42052: Fix jQuery.fn.click() (#47)
Browse files Browse the repository at this point in the history
* MC-42052: Fix jQuery.fn.click()

* MC-42052: Replace jQuery click shorthand function

Co-authored-by: Sergii Ivashchenko <serg.ivashchenko@gmail.com>
  • Loading branch information
jcuerdo and sivaschenko authored Jun 1, 2021
1 parent 7f7b3d1 commit e7a06d3
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ define([
}
});

$('#store-change-button').click();
$('#store-change-button').trigger('click');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define([
'use strict';

return function (config, element) {
$(element).click(function (event) {
$(element).on('click', function (event) {
var cart = customerData.get('cart'),
customer = customerData.get('customer');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define([
}));
}

$('#customer-edit-delete-button').click(function () {
$('#customer-edit-delete-button').on('click', function () {
var msg = $.mage.__('Are you sure you want to do this?'),
url = $('#customer-edit-delete-button').data('url');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ define([
.find('.giftmessage-area:not(:visible)').each(function (x, element) {
if ($(element).val().length > 0) {
$(element).trigger('change');
container.find('a').click();
container.find('a').trigger('click');
}
});
} else {
Expand All @@ -61,7 +61,7 @@ define([
}).end()
.find('.giftmessage-area').val('').change().end()
.find('.select').val('').change().end()
.find('.checkbox:checked').prop('checked', false).click().prop('checked', false).end()
.find('.checkbox:checked').prop('checked', false).trigger('click').prop('checked', false).end()
.find('.price-box').addClass(this.options.noDisplay).end();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ define([
* Action to close the context menu in media gallery.
*/
closeContextMenu: function () {
$(this.gridSelector).click();
$(this.gridSelector).trigger('click');
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ define([
* Initialize image action events
*/
initEvents: function () {
$(this.imageModel().addSelectedBtnSelector).click(function () {
$(this.imageModel().addSelectedBtnSelector).on('click', function () {
image.insertImage(
this.imageModel().getSelected(),
{
Expand All @@ -81,7 +81,7 @@ define([
}
);
}.bind(this));
$(this.imageModel().deleteSelectedBtnSelector).click(function () {
$(this.imageModel().deleteSelectedBtnSelector).on('click', function () {
this.deleteImageAction(this.imageModel().selected());
}.bind(this));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ define([

if (key === 'enterKey') {
event.preventDefault();
modalElement.find('.page-action-buttons button.save').click();
modalElement.find('.page-action-buttons button.save').trigger('click');
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Msrp/view/base/web/js/msrp.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ define([
ev.preventDefault();

if (this.options.addToCartButton) {
$(this.options.addToCartButton).click();
$(this.options.addToCartButton).trigger('click');
this.closePopup(this.$popup);
}
},
Expand All @@ -199,7 +199,7 @@ define([
this.options.inputQty && !isNaN(this.tierOptions.qty)
) {
$(this.options.inputQty).val(this.tierOptions.qty);
$(this.options.addToCartButton).click();
$(this.options.addToCartButton).trigger('click');
this.closePopup(this.$popup);
}
},
Expand Down Expand Up @@ -280,7 +280,7 @@ define([
}

if (this.options.addToCartButton) {
$(this.options.addToCartButton).click();
$(this.options.addToCartButton).trigger('click');

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ define([
}

if (this.isFullscreen && this.fotoramaItem.data('fotorama').activeFrame.i === number) {
this.fotoramaItem.data('fotorama').activeFrame.$stageFrame[0].click();
this.fotoramaItem.data('fotorama').activeFrame.$stageFrame[0].trigger('click');
}
},

Expand Down Expand Up @@ -748,14 +748,14 @@ define([
if (window.Froogaloop) {
clearInterval(waitForFroogaloop);
fotorama.requestFullScreen();
this.fotoramaItem.data('fotorama').activeFrame.$stageFrame[0].click();
this.fotoramaItem.data('fotorama').activeFrame.$stageFrame[0].trigger('click');
this.Base = false;
}
}, this), 50);
} else { //if not a vimeo - play it immediately with a little lag in case for fotorama fullscreen
setTimeout($.proxy(function () {
fotorama.requestFullScreen();
this.fotoramaItem.data('fotorama').activeFrame.$stageFrame[0].click();
this.fotoramaItem.data('fotorama').activeFrame.$stageFrame[0].trigger('click');
this.Base = false;
}, this), 50);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define([
}).done(function (data) {
$('#product-review-container').html(data).trigger('contentUpdated');
$('[data-role="product-review"] .pages a').each(function (index, element) {
$(element).click(function (event) { //eslint-disable-line max-nested-callbacks
$(element).on('click', function (event) { //eslint-disable-line max-nested-callbacks
processReviews($(element).attr('href'), true);
event.preventDefault();
});
Expand All @@ -49,7 +49,7 @@ define([
}

$(function () {
$('.product-info-main .reviews-actions a').click(function (event) {
$('.product-info-main .reviews-actions a').on('click', function (event) {
var anchor, addReviewBlock;

event.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define([
}));
}

$('#order-view-cancel-button').click(function () {
$('#order-view-cancel-button').on('click', function () {
var msg = $.mage.__('Are you sure you want to cancel this order?'),
url = $('#order-view-cancel-button').data('url');

Expand All @@ -45,13 +45,13 @@ define([
return false;
});

$('#order-view-hold-button').click(function () {
$('#order-view-hold-button').on('click', function () {
var url = $('#order-view-hold-button').data('url');

getForm(url).appendTo('body').trigger('submit');
});

$('#order-view-unhold-button').click(function () {
$('#order-view-unhold-button').on('click', function () {
var url = $('#order-view-unhold-button').data('url');

getForm(url).appendTo('body').trigger('submit');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(
'use strict';

return function (config, element) {
$(element).click(config, function () {
$(element).on('click', config, function () {
confirmSetLocation(config.message, config.url);
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ define([
*/
$(container).on('click', '.btn_choose_file_upload', function () {
swatchComponents.inputFile.attr('data-called-by', $(this).data('class'));
swatchComponents.inputFile.click();
swatchComponents.inputFile.trigger('click');
});

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Swatches/view/adminhtml/web/js/visual.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ define([
*/
$(document).on('click', '.btn_choose_file_upload', function () {
swatchComponents.inputFile.attr('data-called-by', $(this).attr('id'));
swatchComponents.inputFile.click();
swatchComponents.inputFile.trigger('click');
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ define([
* @param {Event} e
*/
triggerImageUpload: function (imageUploader, e) {
$(e.target).closest('.file-uploader').find('input[type="file"]').click();
$(e.target).closest('.file-uploader').find('input[type="file"]').trigger('click');
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define([
expect(result).toEqual(wdContainer[0]);
done();
});
link.click();
link.trigger('click');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ define([
it('Check add new address event', function () {
Obj = new MultiShipping({});
Obj.element = jasmine.createSpyObj('element', ['submit']);
addNewAddressBtn.click();
addNewAddressBtn.trigger('click');

expect(Obj.element.submit).toHaveBeenCalled();
expect(addressflag.val()).toBe('1');
Expand All @@ -109,7 +109,7 @@ define([
it('Check can continue event', function () {
Obj = new MultiShipping({});
Obj.element = jasmine.createSpyObj('element', ['submit']);
canContinueBtn.click();
canContinueBtn.trigger('click');

expect(Obj.element.submit).not.toHaveBeenCalled();
expect(canContinueFlag.val()).toBe('1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ define([
it('Check cancel action', function () {
var cancel = spyOn(widget.options.actions, 'cancel');

jQuery('.modals-overlay').click();
jQuery('.modals-overlay').trigger('click');
expect(widget.options.outerClickHandler).toBeDefined();
expect(cancel).toHaveBeenCalled();
});
Expand Down
2 changes: 1 addition & 1 deletion dev/tests/js/jasmine/tests/lib/mage/multiselect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ define([

spyOn(instance.data('mage-multiselect2'), '_createSelectedOption').and.returnValue(true);

checkbox.click();
checkbox.trigger('click');

expect(instance.data('mage-multiselect2')._createSelectedOption).toHaveBeenCalledWith({
value: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
create: function(context) {
return {
CallExpression: function(node) {
let names = ['blur', 'focus', 'focusin', 'focusout', 'resize', 'scroll', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'change', 'select', 'submit', 'keydown', 'keypress', 'keyup', 'contextmenu'],
let names = ['blur', 'focus', 'focusin', 'focusout', 'resize', 'scroll', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'change', 'select', 'submit', 'keydown', 'keypress', 'keyup', 'contextmenu', 'click'],
name
if (node.callee.type !== 'MemberExpression') return
if (!names.includes(node.callee.property.name)) return
Expand Down
4 changes: 2 additions & 2 deletions lib/web/mage/adminhtml/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ define([
contentBlock.html(data).trigger('contentUpdated');

if (uploaded) {
contentBlock.find('.filecnt:last').click();
contentBlock.find('.filecnt:last').trigger('click');
}
});
},
Expand All @@ -244,7 +244,7 @@ define([
* @param {jQuery.Event} event
*/
selectFolder: function (event) {
this.element.find('[data-id="' + $(event.currentTarget).data('node').id + '"]>a').click();
this.element.find('[data-id="' + $(event.currentTarget).data('node').id + '"]>a').trigger('click');
},

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/web/mage/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ define([
}
}
$(switches).each(function (ind, el) {
$(el).click(function (event) {
$(el).on('click', function (event) {
event.preventDefault();
showItem(ind);
});
Expand Down

0 comments on commit e7a06d3

Please sign in to comment.