You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
314 lines
10 KiB
314 lines
10 KiB
'use strict';
|
|
|
|
(function ($) {
|
|
const metaLocale = document.querySelector('meta[property="og:locale"]');
|
|
const localeValue = metaLocale.getAttribute('content');
|
|
|
|
// Login
|
|
|
|
$('.login_popup').on('click', function(e){
|
|
e.preventDefault();
|
|
$('.login_modal').addClass('active');
|
|
});
|
|
$('.login_close').on('click', function(){
|
|
$('.login_modal').removeClass('active');
|
|
});
|
|
$('.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').removeClass('error');
|
|
});
|
|
$('.js-get-code').on('click', function(){
|
|
$('.login_input').removeClass('error');
|
|
|
|
var email = $('.js-input-email input').val();
|
|
$('.sended_email').text(email);
|
|
|
|
if(email === '') {
|
|
$('.js-input-email').addClass('error');
|
|
$('.js-input-email .login_error').text(localeValue == 'en_US' ? 'Enter your email' : 'Укажите Email');
|
|
return false;
|
|
} else {
|
|
// Проверка Email
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/wp-admin/admin-ajax.php',
|
|
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;
|
|
} else {
|
|
$('.login_wrap .step').toggleClass('active');
|
|
send_code();
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
$('.js-repeat-code').on('click', function(){
|
|
$('.login_input').removeClass('error');
|
|
send_code();
|
|
});
|
|
|
|
function send_code(){
|
|
$('.login_timer').show();
|
|
$('.js-repeat-code').hide();
|
|
$('.login_back').addClass('disabled');
|
|
// Timer
|
|
var seconds = 15;
|
|
var interval = setInterval(function() {
|
|
if (seconds > 0) {
|
|
seconds--;
|
|
$('.seconds').text(seconds);
|
|
} else {
|
|
clearInterval(interval);
|
|
$('.login_timer').hide();
|
|
$('.js-repeat-code').show();
|
|
$('.login_back').removeClass('disabled');
|
|
$('.seconds').text(15);
|
|
}
|
|
}, 1000);
|
|
//Ajax отправка кода
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/wp-admin/admin-ajax.php',
|
|
data: {action: 'send_code', email: $('.js-input-email input').val()}
|
|
});
|
|
}
|
|
// Проверка кода и регистрация/авторизация
|
|
$('.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) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/wp-admin/admin-ajax.php',
|
|
data: {action: 'check_code', code: val, email: email},
|
|
success: function(data){
|
|
console.log(data);
|
|
if(data['status'] == 'success_reg') {
|
|
$('.login_forms').addClass('hide');
|
|
$('.login_success').removeClass('hide');
|
|
if (typeof wc_checkout_params !== 'undefined') {
|
|
location.reload()
|
|
}
|
|
}
|
|
if(data['status'] == 'success_auth') {
|
|
$('.login_forms').addClass('hide');
|
|
$('.login_auth').removeClass('hide');
|
|
if (typeof wc_checkout_params !== 'undefined') {
|
|
location.reload()
|
|
}
|
|
}
|
|
if(data['status'] == 'error') {
|
|
$('.js-input-code').addClass('error');
|
|
$('.js-input-code .login_error').text(data['text']);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
$('.email_link_form').on('submit', function(e){
|
|
e.preventDefault();
|
|
$('.cabinet-card_linked-email .error').remove();
|
|
var data = $(this).serializeArray();
|
|
$.ajax({
|
|
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>');
|
|
} else {
|
|
location.reload();
|
|
}
|
|
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
})(jQuery);
|
|
|
|
function checkImage(imageSrc, good) {
|
|
var img = new Image();
|
|
img.onload = good;
|
|
img.src = imageSrc;
|
|
}
|
|
// 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');
|
|
// header
|
|
|
|
|
|
|
|
|
|
|
|
function initOverlay(){
|
|
|
|
// overlay
|
|
let products = document.querySelectorAll('.product__item');
|
|
|
|
products.forEach(productItem => {
|
|
let button = productItem.querySelector('.open-overlay'),
|
|
overlay = productItem.querySelector('.product-item__overlay');
|
|
|
|
|
|
if (button) {
|
|
button.onclick = function (e) {
|
|
document.querySelectorAll('.product__item').forEach(e => {
|
|
if (e.classList.contains('active')) {
|
|
e.classList.remove('active');
|
|
}
|
|
});
|
|
document.querySelectorAll('.product-item__overlay').forEach(e => {
|
|
if (e.classList.contains('active')) {
|
|
e.classList.remove('active');
|
|
}
|
|
});
|
|
|
|
productItem.classList.toggle('active');
|
|
overlay.classList.toggle('active');
|
|
}
|
|
}
|
|
|
|
})
|
|
// overlay
|
|
}
|
|
|
|
initOverlay()
|
|
|
|
|
|
function initSelect(){
|
|
|
|
|
|
// select
|
|
toggleOpenX('.select', '.select__state' , '.state__content', '.state__block', true);
|
|
|
|
let selects = document.querySelectorAll('.select');
|
|
|
|
selects.forEach(select => {
|
|
let state = select.querySelector('.select__state'),
|
|
content = select.querySelector('.state__block'),
|
|
buttons = select.querySelectorAll('.state__button');
|
|
|
|
buttons.forEach(e => {
|
|
let button = e;
|
|
|
|
e.onclick = function (event) {
|
|
event.preventDefault();
|
|
|
|
buttons.forEach(element => {
|
|
if (element.classList.contains('active')) {
|
|
element.classList.remove('active');
|
|
}
|
|
})
|
|
|
|
let text = e.textContent.trim();
|
|
state.value = text;
|
|
|
|
button.classList.add('active');
|
|
content.style.height = 0;
|
|
select.classList.remove('active');
|
|
}
|
|
})
|
|
})
|
|
|
|
// select
|
|
}
|
|
initSelect()
|
|
|
|
function toggleOpenX(mainElement, buttonElement ,heightElement, contentElement, close) {
|
|
let elements = document.querySelectorAll(mainElement);
|
|
|
|
elements.forEach(e => {
|
|
let thisMainElement = e,
|
|
thisButtonElement = e.querySelector(buttonElement),
|
|
thisHeightElement = e.querySelector(heightElement),
|
|
thisContentElement = e.querySelector(contentElement);
|
|
|
|
thisButtonElement.onclick = function (e) {
|
|
let height = thisHeightElement.clientHeight;
|
|
|
|
if (close == true && !thisMainElement.classList.contains('active')) {
|
|
elements.forEach(e => {
|
|
if (e.classList.contains('active')) {
|
|
e.classList.remove('active');
|
|
e.querySelector(contentElement).style.height = null
|
|
}
|
|
})
|
|
}
|
|
|
|
if (!thisMainElement.classList.contains('active')) {
|
|
thisContentElement.style.height = `${height}px`;
|
|
thisMainElement.classList.add('active');
|
|
}else{
|
|
thisContentElement.style.height = null;
|
|
thisMainElement.classList.remove('active');
|
|
}
|
|
}
|
|
|
|
});
|
|
}
|
|
var menu_opened = false;
|
|
function toggleHeader(button, content, blockheight, removeBlock, removeClass) {
|
|
let thisButton = document.querySelector(button),
|
|
thisContent = document.querySelector(content),
|
|
thisRemoveBlock = document.querySelector(removeBlock) || '',
|
|
thisBlockheight = document.querySelector(blockheight);
|
|
|
|
thisButton.onclick = function () {
|
|
let height = thisBlockheight.clientHeight;
|
|
|
|
if (!thisContent.classList.contains('open')) {
|
|
thisContent.style.height = `${height}px`;
|
|
thisContent.classList .add('open');
|
|
|
|
if (removeBlock) {
|
|
thisRemoveBlock.classList.remove(removeClass);
|
|
}
|
|
}else{
|
|
thisContent.style.height = null;
|
|
thisContent.classList.remove('open');
|
|
|
|
if (removeBlock) {
|
|
if (window.Y <= 25) {
|
|
thisRemoveBlock.classList.add(removeClass);
|
|
}
|
|
}
|
|
}
|
|
menu_opened = !menu_opened;
|
|
}
|
|
}
|
|
|
|
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 (scroll >= 25) {
|
|
header.classList.remove('white')
|
|
}else{
|
|
|
|
header.classList.add('white')
|
|
|
|
}
|
|
}
|
|
|
|
});
|
|
}
|
|
// scroll
|
|
|
|
|
|
|
|
|
|
|