45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
define([
|
|
'jquery',
|
|
'Magento_Ui/js/modal/alert'
|
|
], function ($, alert) {
|
|
'use strict';
|
|
|
|
return function (config) {
|
|
var buttonSelector = 'button.action.tocart, [data-role="esun-buy-now"], #top-cart-btn-checkout',
|
|
formSelector = '[data-role="tocart-form"], #product_addtocart_form';
|
|
|
|
function showNotice() {
|
|
var content = $('<p>', {
|
|
'class': 'esun-test-mode-modal__message',
|
|
text: config.message
|
|
}).prop('outerHTML');
|
|
|
|
alert({
|
|
modalClass: 'esun-test-mode-modal',
|
|
title: config.title,
|
|
content: content
|
|
});
|
|
}
|
|
|
|
document.addEventListener('click', function (event) {
|
|
if (event.target.closest(buttonSelector)) {
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
showNotice();
|
|
}
|
|
}, true);
|
|
|
|
document.addEventListener('submit', function (event) {
|
|
if (event.target.matches(formSelector)) {
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
showNotice();
|
|
}
|
|
}, true);
|
|
|
|
if (new URLSearchParams(window.location.search).get('purchase_test_mode') === '1') {
|
|
showNotice();
|
|
}
|
|
};
|
|
});
|