Maks | formating files and add TO_DO

pull/36/head
Антон 1 month ago
parent 3c41995cb6
commit e3f48095fb
  1. 7
      wp-content/themes/cosmopet/global-functions/multisite-functions.php
  2. 93
      wp-content/themes/cosmopet/modules/footer/assets/js/footer.js

@ -124,8 +124,7 @@ if($site_env->site_mode == 'production' and $site_env->site_region == 'ae') {
});
});
</script>
<?php
}
<? }
// 2. Событие Purchase (Покупка)
if (is_wc_endpoint_url('order-received')) {
@ -191,8 +190,7 @@ if($site_env->site_mode == 'production' and $site_env->site_region == 'ae') {
});
});
</script>
<?php
}
<? }
}
/* Передача контрибуции со страницы "Спасибо" */
@ -255,6 +253,7 @@ if($site_env->site_mode == 'production' and $site_env->site_region == 'ae') {
}
}
// TO_DO: удалить, если не нужно
// Отключаем кэширование для страниц товаров
add_action('template_redirect', function() {
if (is_product()) {

@ -7,34 +7,35 @@
// Флаг для предотвращения множественной обработки
let isProcessing = false;
// TO_DO : вынести логику в модуль авторизации/регистрации
// Login
$('.login_popup').on('click', function(e){
$('.login_popup').on('click', function (e) {
e.preventDefault();
$('.login_modal').addClass('active');
});
$('.login_close').on('click', function(){
$('.login_close').on('click', function () {
$('.login_modal').removeClass('active');
$('.login_forms').removeClass('hide');
$('.login_success').addClass('hide');
$('.login_auth').addClass('hide');
isProcessing = false; // Сбрасываем флаг при закрытии
});
$('.login_back').on('click', function(){
if($(this).is('.disabled')) {
$('.login_back').on('click', function () {
if ($(this).is('.disabled')) {
return false;
}
$('.login_wrap .step').toggleClass('active');
});
$('.login_input input').on('input keyup', function(){
$('.login_input input').on('input keyup', function () {
$('.login_input').removeClass('error');
});
$('.js-get-code').on('click', function(){
$('.js-get-code').on('click', function () {
$('.login_input').removeClass('error');
var email = $('.js-input-email input').val();
$('.sended_email').text(email);
if(email === '') {
if (email === '') {
$('.js-input-email').addClass('error');
$('.js-input-email .login_error').text(localeValue == 'en_US' ? 'Enter your email' : 'Укажите Email');
return false;
@ -43,9 +44,9 @@
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
data: {action: 'email_validate', email:email},
success: function(data){
if(data['status'] === 'error') {
data: { action: 'email_validate', email: email },
success: function (data) {
if (data['status'] === 'error') {
$('.js-input-email').addClass('error');
$('.js-input-email .login_error').text(data['text']);
return false;
@ -57,18 +58,18 @@
});
}
});
$('.js-repeat-code').on('click', function(){
$('.js-repeat-code').on('click', function () {
$('.login_input').removeClass('error');
send_code();
});
function send_code(){
function send_code() {
$('.login_timer').show();
$('.js-repeat-code').hide();
$('.login_back').addClass('disabled');
// Timer
var seconds = 15;
var interval = setInterval(function() {
var interval = setInterval(function () {
if (seconds > 0) {
seconds--;
$('.seconds').text(seconds);
@ -84,36 +85,36 @@
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
data: {action: 'send_code', email: $('.js-input-email input').val()}
data: { action: 'send_code', email: $('.js-input-email input').val() }
});
}
// Проверка кода и регистрация/авторизация
$('.js-input-code input').on('input keydown keyup propertychange paste cut copy change', function(){
$('.js-input-code input').on('input keydown keyup propertychange paste cut copy change', function () {
var val = $(this).val();
var email = $('.js-input-email input').val();
if(val.length === 4 && !isProcessing) {
if (val.length === 4 && !isProcessing) {
isProcessing = true; // Устанавливаем флаг, чтобы предотвратить повторную обработку
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
data: {action: 'check_code', code: val, email: email},
success: function(data){
data: { action: 'check_code', code: val, email: email },
success: function (data) {
console.log('Server response:', data); // Отладка ответа сервера
if(data['status'] === 'success_reg') {
if (data['status'] === 'success_reg') {
$('.login_forms').addClass('hide');
$('.login_success').removeClass('hide');
$('.login_auth').addClass('hide'); // Гарантируем, что login_auth скрыт
if (typeof wc_checkout_params !== 'undefined') {
location.reload();
}
} else if(data['status'] === 'success_auth' && !$('.login_success').is(':visible')) {
} else if (data['status'] === 'success_auth' && !$('.login_success').is(':visible')) {
$('.login_forms').addClass('hide');
$('.login_auth').removeClass('hide');
$('.login_success').addClass('hide'); // Гарантируем, что login_success скрыт
if (typeof wc_checkout_params !== 'undefined') {
location.reload();
}
} else if(data['status'] === 'error') {
} else if (data['status'] === 'error') {
$('.js-input-code').addClass('error');
$('.js-input-code .login_error').text(data['text']);
isProcessing = false; // Сбрасываем флаг при ошибке
@ -124,7 +125,7 @@
isProcessing = false; // Сбрасываем флаг при неожиданном статусе
}
},
error: function(xhr, status, error) {
error: function (xhr, status, error) {
console.error('AJAX error:', error); // Отладка ошибок AJAX
$('.js-input-code').addClass('error');
$('.js-input-code .login_error').text(localeValue == 'en_US' ? 'Server error' : 'Ошибка сервера');
@ -134,7 +135,7 @@
}
});
$('.email_link_form').on('submit', function(e){
$('.email_link_form').on('submit', function (e) {
e.preventDefault();
$('.cabinet-card_linked-email .error').remove();
var data = $(this).serializeArray();
@ -142,9 +143,9 @@
type: 'POST',
url: '/wp-admin/admin-ajax.php',
data: data,
success: function(data){
if(data['error']) {
$('.cabinet-card_linked-email').append('<div class="cabinet-card__status cabinet-card__status--cancelled error">'+data['error']+'</div>');
success: function (data) {
if (data['error']) {
$('.cabinet-card_linked-email').append('<div class="cabinet-card__status cabinet-card__status--cancelled error">' + data['error'] + '</div>');
} else {
location.reload();
}
@ -160,20 +161,20 @@ function checkImage(imageSrc, good) {
}
// header
toggleOpenX('.lang', '.lang__open', '.lang__list', '.lang__content', false);
toggleHeader('#pc-menu','.header__menu-block','.header__pc-menu', '.white', 'white');
toggleHeader('#phone-menu','.header__menu-block','.header__phone-menu', '.white', 'white');
toggleHeader('#pc-menu', '.header__menu-block', '.header__pc-menu', '.white', 'white');
toggleHeader('#phone-menu', '.header__menu-block', '.header__phone-menu', '.white', 'white');
// header
function initOverlay(){
function initOverlay() {
// overlay
let products = document.querySelectorAll('.product__item');
let products = document.querySelectorAll('.product__item');
products.forEach(productItem => {
products.forEach(productItem => {
let button = productItem.querySelector('.open-overlay'),
overlay = productItem.querySelector('.product-item__overlay');
@ -196,22 +197,22 @@ products.forEach(productItem => {
}
}
})
// overlay
})
// overlay
}
initOverlay()
function initSelect(){
function initSelect() {
// select
toggleOpenX('.select', '.select__state' , '.state__content', '.state__block', true);
// select
toggleOpenX('.select', '.select__state', '.state__content', '.state__block', true);
let selects = document.querySelectorAll('.select');
let selects = document.querySelectorAll('.select');
selects.forEach(select => {
selects.forEach(select => {
let state = select.querySelector('.select__state'),
content = select.querySelector('.state__block'),
buttons = select.querySelectorAll('.state__button');
@ -236,13 +237,13 @@ selects.forEach(select => {
select.classList.remove('active');
}
})
})
})
// select
// select
}
initSelect()
function toggleOpenX(mainElement, buttonElement ,heightElement, contentElement, close) {
function toggleOpenX(mainElement, buttonElement, heightElement, contentElement, close) {
let elements = document.querySelectorAll(mainElement);
elements.forEach(e => {
@ -266,7 +267,7 @@ function toggleOpenX(mainElement, buttonElement ,heightElement, contentElement,
if (!thisMainElement.classList.contains('active')) {
thisContentElement.style.height = `${height}px`;
thisMainElement.classList.add('active');
}else{
} else {
thisContentElement.style.height = null;
thisMainElement.classList.remove('active');
}
@ -286,12 +287,12 @@ function toggleHeader(button, content, blockheight, removeBlock, removeClass) {
if (!thisContent.classList.contains('open')) {
thisContent.style.height = `${height}px`;
thisContent.classList .add('open');
thisContent.classList.add('open');
if (removeBlock) {
thisRemoveBlock.classList.remove(removeClass);
}
}else{
} else {
thisContent.style.height = null;
thisContent.classList.remove('open');
@ -309,10 +310,10 @@ if (document.querySelector('.header').classList.contains('white')) {
window.addEventListener("scroll", function (e) {
let header = document.querySelector('.header');
let scroll = window.scrollY;
if(!menu_opened){
if (!menu_opened) {
if (scroll >= 25) {
header.classList.remove('white')
}else{
} else {
header.classList.add('white')

Loading…
Cancel
Save