| Server IP : 104.171.130.249 / Your IP : 216.73.216.146 Web Server : nginx/1.25.5 System : Linux 0dac65491b7e 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/themes/matreshka/assets/js/ |
Upload File : |
(function ($) {
'use strict';
var $overlay = $('#substitution-overlay');
var $modal = $('#substitution-modal');
var labels = {
call_replace: 'Позвонить и заменить',
no_replace: 'Не заменять',
auto_replace: 'Не спрашивать и заменить'
};
/* ── Open / Close ───────────────────────────────────── */
function openModal() {
$overlay.addClass('open');
// Small delay so CSS transition fires after display:block
requestAnimationFrame(function () {
$modal.addClass('open');
});
$('body').css('overflow', 'hidden');
}
function closeModal() {
$modal.removeClass('open');
$overlay.removeClass('open');
$('body').css('overflow', '');
}
$(document).on('click', '#btn-substitution-modal', function (e) {
e.preventDefault();
openModal();
});
$(document).on('click', '#substitution-modal-close, #substitution-overlay', function () {
closeModal();
});
// Close on Escape
$(document).on('keydown', function (e) {
if (e.key === 'Escape' && $modal.hasClass('open')) {
closeModal();
}
});
/* ── Radio selection ────────────────────────────────── */
$(document).on('change', 'input[name="substitution_type"]', function () {
var $group = $(this).closest('.substitution-radio-group');
$group.find('.substitution-radio-item').removeClass('active');
$(this).closest('.substitution-radio-item').addClass('active');
});
/* ── Checkbox (bag options) toggle ──────────────────── */
$(document).on('change', '.substitution-bag-item input[type="checkbox"]', function () {
$(this).closest('.substitution-bag-item').toggleClass('active', this.checked);
});
/* ── Done button — save via AJAX, close ─────────────── */
$(document).on('click', '#substitution-modal-done', function () {
var data = {
action: 'matreshka_save_substitution',
security: matreshka_ajax.nonce,
substitution: $('input[name="substitution_type"]:checked').val() || 'call_replace',
comment: $('#substitution-comment').val(),
less_bags: $('input[name="less_bags"]').is(':checked') ? 1 : 0,
vegs_in_bags: $('input[name="vegs_in_bags"]').is(':checked') ? 1 : 0
};
// Update label on the trigger button immediately
$('#substitution-current-label').text(labels[data.substitution] || labels.call_replace);
$.post(matreshka_ajax.ajax_url, data);
closeModal();
});
/* ── Re-bind after WC AJAX cart refresh ─────────────── */
$(document.body).on('updated_cart_totals', function () {
$overlay = $('#substitution-overlay');
$modal = $('#substitution-modal');
});
})(jQuery);