var $=jQuery.noConflict();
(function(){
function initPlatformSliderSwipe(){
const slider=document.querySelector('.platform-slider');
const track=slider ? slider.querySelector('.carousel-inner'):null;
if(!slider||!track||!window.bootstrap||!window.bootstrap.Carousel||!window.PointerEvent){
return;
}
const carousel=window.bootstrap.Carousel.getOrCreateInstance(slider, {
interval: false,
touch: false,
wrap: true
});
const threshold=48;
let pointerId=null;
let startX=0;
let startY=0;
let directionLocked=false;
function resetGesture(){
pointerId=null;
directionLocked=false;
}
track.addEventListener('pointerdown', function(event){
if(event.pointerType!=='touch'&&event.pointerType!=='pen'){
return;
}
pointerId=event.pointerId;
startX=event.clientX;
startY=event.clientY;
directionLocked=false;
track.setPointerCapture(event.pointerId);
});
track.addEventListener('pointermove', function(event){
if(event.pointerId!==pointerId){
return;
}
const deltaX=event.clientX - startX;
const deltaY=event.clientY - startY;
if(!directionLocked&&Math.abs(deltaX) > 12&&Math.abs(deltaX) > Math.abs(deltaY)){
directionLocked=true;
}
if(directionLocked){
event.preventDefault();
}}, { passive: false });
track.addEventListener('pointerup', function(event){
if(event.pointerId!==pointerId){
return;
}
const deltaX=event.clientX - startX;
if(directionLocked&&Math.abs(deltaX) >=threshold){
if(deltaX < 0){
carousel.next();
}else{
carousel.prev();
}}
resetGesture();
});
track.addEventListener('pointercancel', resetGesture);
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded', initPlatformSliderSwipe, { once: true });
}else{
initPlatformSliderSwipe();
}})();
$('.types-wrap div.filter-country').on('click', function(){
var hash=$(this).attr('data-href');
if((hash!="")&&(hash!=undefined))
window.location.href=hash;
});
$.each(jQuery(".header-menu-el a"), function(){
if(this.href==location.href){
$(this).addClass('actual');
};});
$(document).ready(function(){
$(window).scroll(function(){
var scroll=$(window).scrollTop();
if(scroll >=30){
$(".tophead_banner").addClass("scrolled_top");
$(".header").addClass("smallheader");
}else{
$(".tophead_banner").removeClass("scrolled_top");
$(".header").removeClass("smallheader");
}});
});
$(document).ready(function(){
$('.accordion-list').each(function(){
const $accordion=$(this);
const $buttons=$accordion.find('.accordion-button');
const reduceMotion=window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function nextTransitionToken(answer){
const token=Number(answer.dataset.accordionTransition||0) + 1;
answer.dataset.accordionTransition=String(token);
return token;
}
function finishWhenSettled(answer, token, callback){
const finish=function(event){
if(event&&(event.target!==answer||event.propertyName!=='opacity')){
return;
}
if(answer.dataset.accordionTransition!==String(token)){
return;
}
answer.removeEventListener('transitionend', finish);
callback();
};
answer.addEventListener('transitionend', finish);
window.setTimeout(finish, 220);
}
function openAnswer(answer){
if(reduceMotion){
answer.hidden=false;
return;
}
const token=nextTransitionToken(answer);
answer.hidden=false;
answer.classList.add('is-animating');
answer.style.opacity='0';
answer.style.transform='translateY(4px)';
window.requestAnimationFrame(function(){
if(answer.dataset.accordionTransition!==String(token)){
return;
}
answer.style.opacity='1';
answer.style.transform='translateY(0)';
});
finishWhenSettled(answer, token, function(){
answer.classList.remove('is-animating');
answer.style.opacity='';
answer.style.transform='';
});
}
function closeAnswer(answer){
if(answer.hidden){
return;
}
if(reduceMotion){
answer.hidden=true;
return;
}
const token=nextTransitionToken(answer);
answer.classList.add('is-animating');
answer.style.opacity='1';
answer.style.transform='translateY(0)';
window.requestAnimationFrame(function(){
if(answer.dataset.accordionTransition!==String(token)){
return;
}
answer.style.opacity='0';
answer.style.transform='translateY(4px)';
});
finishWhenSettled(answer, token, function(){
answer.hidden=true;
answer.classList.remove('is-animating');
answer.style.opacity='';
answer.style.transform='';
});
}
$buttons.each(function(){
const $button=$(this);
const answerId=$button.attr('aria-controls');
const answer=answerId ? document.getElementById(answerId):null;
if(answer){
answer.hidden=$button.attr('aria-expanded')!=='true';
}});
$buttons.on('click', function(){
const $button=$(this);
const isExpanded=$button.attr('aria-expanded')==='true';
$buttons.not($button).each(function(){
const $otherButton=$(this);
const otherAnswer=document.getElementById($otherButton.attr('aria-controls'));
$otherButton.attr('aria-expanded', 'false').closest('li').removeClass('active');
if(otherAnswer){
closeAnswer(otherAnswer);
}});
const answer=document.getElementById($button.attr('aria-controls'));
$button.attr('aria-expanded', String(!isExpanded)).closest('li').toggleClass('active', !isExpanded);
if(answer){
if(isExpanded){
closeAnswer(answer);
}else{
openAnswer(answer);
}}
});
});
});
(function(){
function initHomeScrollMotion(){
if(!document.body.classList.contains('home') ||
!('IntersectionObserver' in window) ||
window.matchMedia('(prefers-reduced-motion: reduce)').matches){
return;
}
const sections=document.querySelectorAll([
'.main_block_three',
'.main_block_four',
'.main_block_five',
'.main_block_six',
'.main_block_seven',
'.main_block_eight',
'.main_block_nine',
'.main_block_eleven',
'.main_block_twelve',
'.main_block_thirteen'
].join(','));
const observer=new IntersectionObserver(function(entries){
entries.forEach(function(entry){
if(!entry.isIntersecting){
return;
}
entry.target.classList.add('is-visible');
observer.unobserve(entry.target);
});
}, {
rootMargin: '0px 0px -8% 0px',
threshold: 0.05
});
sections.forEach(function(section){
if(section.getBoundingClientRect().top < window.innerHeight * 0.9){
return;
}
section.classList.add('home-reveal');
observer.observe(section);
});
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded', initHomeScrollMotion, { once: true });
}else{
initHomeScrollMotion();
}})();
const menuBtn=$('.mob-menu'),
menu=$('.header-menu'),
blur=$('.content-page-blur'),
menuBackdrop=$('.header-menu-backdrop');
const menuFocusableSelector='a[href], button:not([disabled]), [tabindex]:not([tabindex="-1"])';
function setMobileMenuScrollLock(isOpen){
const $html=$('html');
const $body=$('body');
$html.add($body).toggleClass('menu-open', isOpen);
}
function preventBackgroundScrollWhileMenuOpen(event){
if(!menu.length||!menu.hasClass('opened')||menu[0].contains(event.target)){
return;
}
event.preventDefault();
}
document.addEventListener('wheel', preventBackgroundScrollWhileMenuOpen, { passive: false });
document.addEventListener('touchmove', preventBackgroundScrollWhileMenuOpen, { passive: false });
function setMobileMenuBackgroundInert(isOpen){
const $targets=$('.content-page-blur, .footer, .header-logo, .full_contacts, .btn_header, #conarium-contact-widget-button, #conarium-contact-widget-panel');
$targets.each(function(){
if(isOpen){
if(!this.hasAttribute('data-menu-previous-aria-hidden')){
const previousValue=this.getAttribute('aria-hidden');
this.setAttribute('data-menu-previous-aria-hidden', previousValue===null ? '':previousValue);
}
this.setAttribute('aria-hidden', 'true');
this.inert=true;
return;
}
if(this.hasAttribute('data-menu-previous-aria-hidden')){
const previousValue=this.getAttribute('data-menu-previous-aria-hidden');
if(previousValue){
this.setAttribute('aria-hidden', previousValue);
}else{
this.removeAttribute('aria-hidden');
}
this.removeAttribute('data-menu-previous-aria-hidden');
}
this.inert=false;
});
}
function getMobileMenuFocusables(){
return menuBtn.add(menu.find(menuFocusableSelector)).filter(function(){
return $(this).is(':visible');
});
}
function trapMobileMenuFocus(event){
const $focusables=getMobileMenuFocusables();
const first=$focusables[0];
const last=$focusables[$focusables.length - 1];
if(!first||!last){
event.preventDefault();
menuBtn.trigger('focus');
return;
}
if(event.shiftKey&&document.activeElement===first){
event.preventDefault();
$(last).trigger('focus');
}else if(!event.shiftKey&&document.activeElement===last){
event.preventDefault();
$(first).trigger('focus');
}}
function setMobileMenuOpen(isOpen, restoreFocus){
menu.toggleClass('opened', isOpen);
menuBtn.toggleClass('opened', isOpen)
.attr('aria-expanded', String(isOpen))
.attr('aria-label', isOpen ? 'Закрыть меню':'Открыть меню');
blur.toggleClass('blur_page', isOpen);
setMobileMenuScrollLock(isOpen);
menuBackdrop.toggleClass('is-active', isOpen).attr('aria-hidden', String(!isOpen));
setMobileMenuBackgroundInert(isOpen);
if(!isOpen&&restoreFocus){
menuBtn.trigger('focus');
}}
menuBtn.on('click', function(){
const willOpen = !menu.hasClass('opened');
setMobileMenuOpen(willOpen, !willOpen);
});
$('.close_mob_menu').on('click', function(){
setMobileMenuOpen(false, false);
});
menuBackdrop.on('click', function(e){
e.preventDefault();
e.stopPropagation();
setMobileMenuOpen(false, true);
});
$(document).click(function (e){
if(!menuBtn.is(e.target)&&menuBtn.has(e.target).length===0&&!menu.is(e.target)&&menu.has(e.target).length===0){
setMobileMenuOpen(false);
}});
$(document).on('keydown', function(e){
if(!menu.hasClass('opened')){
return;
}
if(e.key==='Tab'){
trapMobileMenuFocus(e);
}
if(e.key==='Escape'){
setMobileMenuOpen(false, true);
return;
}
if((!menu.length||!menu[0].contains(document.activeElement)) &&
[' ', 'PageDown', 'PageUp', 'Home', 'End', 'ArrowDown', 'ArrowUp'].includes(e.key)
){
e.preventDefault();
}});
$(window).on('resize', function(){
if(window.matchMedia('(min-width: 992px)').matches&&menu.hasClass('opened')){
setMobileMenuOpen(false, false);
}});
$('html,body').ready(function(){
const $reviewCards=$('.comments-card__content-body');
if(!$.fn.readmore||!$reviewCards.length){
return;
}
$reviewCards.readmore({
speed: 250,
maxHeight: 145,
heightMargin: 16,
moreLink: '<a href="#">Читать далее</a>',
lessLink: '<a href="#">Скрыть</a>'
});
});
$('.modal_name_list_group_btn_1').on("click", function(e){
e.preventDefault();
if($(this).text()=='Расскрыть список'){
$('.modal_name_list_group_hidden_1').addClass('list_active_group');
$(this).text('Свернуть список')
}else{
$('.modal_name_list_group_hidden_1').removeClass('list_active_group');
$(this).text('Расскрыть список')
}});
$('.modal_name_list_group_btn_2').on("click", function(e){
e.preventDefault();
if($(this).text()=='Расскрыть список'){
$('.modal_name_list_group_hidden_2').addClass('list_active_group');
$(this).text('Свернуть список')
}else{
$('.modal_name_list_group_hidden_2').removeClass('list_active_group');
$(this).text('Расскрыть список')
}});
$('#scroll_left_arrow').click(function (){
$("#comments_slider").animate({
scrollLeft: '-=386px'
});
});
$('#scroll_right_arrow').click(function (){
$("#comments_slider").animate({
scrollLeft: '+=386px'
});
});
$(document).ready(function(){
const $reviewTabs=$('#comment_seven, #video_seven');
const $commentsPanel=$('#comments_slider_block');
const $videoPanel=$('#video_slider');
if(!$reviewTabs.length){
return;
}
function selectReviewTab($tab){
const showVideo=$tab.attr('id')==='video_seven';
$reviewTabs.removeClass('active').attr('aria-selected', 'false');
$tab.addClass('active').attr('aria-selected', 'true');
$commentsPanel.prop('hidden', showVideo);
$videoPanel.prop('hidden', !showVideo);
}
selectReviewTab($('#comment_seven'));
$reviewTabs.on('click', function(){
selectReviewTab($(this));
});
});
$('#myModal').on('shown.bs.modal', function(){
$('#myInput').trigger('focus')
})
if(!document.body.classList.contains('single-post')&&typeof window.lepopup_add_event==='function'){
window.lepopup_add_event("onload", {
item:        "Have-a-quest-2021",
item_mobile: "Have-a-quest-mob-2021",
mode:        "once-period",
period:      24,
delay:       60,
close_delay: 0,
onSuccess: function(){
if(typeof window.ym==='function'){
window.ym(73955662, 'reachGoal', 'lead-catcher');
}}
});
}
$('.zayav_text__btn').on("click", function(e){
e.preventDefault();
if($(this).text()=='Открыть полностью'){
$('.zayav_text__none').addClass('zayav_text__active');
$(this).text('Свернуть текст')
}else{
$('.zayav_text__none').removeClass('zayav_text__active');
$(this).text('Открыть полностью')
}});
var carousel=$('#carousel_vid_slider'),
threshold=150,
slideWidth=230,
dragStart,
dragEnd;
$('#next_vid_slider').click(function(){
shiftSlide(-1);
})
$('#prev_vid_slider').click(function(){
shiftSlide(1);
})
$(document).on('click', '.no-active', function(){
$('#next_vid_slider').click();
})
function shiftSlide(direction){
if(carousel.hasClass('transition_vid_slider')) return;
dragEnd=dragStart;
carousel.addClass('transition_vid_slider')
.css('transform','translateX(' + (direction * slideWidth) + 'px)');
$('.slide_vid_slider').addClass('no-active');
$('.slide_vid_slider video').attr('controls',false);
if(direction===-1){
$('.slide_vid_slider:nth-child(2)').removeClass('no-active');
$('.slide_vid_slider:nth-child(2) video').attr('controls',true);
$('video').trigger('pause');
}else{
$('.slide_vid_slider:last-child').removeClass('no-active');
$('.slide_vid_slider:last-child video').attr('controls',true);
$('video').trigger('pause');
}
setTimeout(function(){
if(direction===1){
$('.slide_vid_slider:first').before($('.slide_vid_slider:last'));
}else if(direction===-1){
$('.slide_vid_slider:last').after($('.slide_vid_slider:first'));
}
carousel.removeClass('transition_vid_slider')
carousel.css('transform','translateX(0px)');
},300)
}
const accordionButtons=$('.accordion-button_footer');
const accordionItems=$('.accordion-item_footer');
function isFooterMobile(){
return window.matchMedia('(max-width: 991px)').matches;
}
function setFooterAccordionState($item, isOpen){
const $button=$item.find('.accordion-button_footer');
const panelId=$button.attr('aria-controls');
const panel=panelId ? document.getElementById(panelId):null;
const shouldOpen=isFooterMobile()&&isOpen;
$item.toggleClass('active', shouldOpen);
$button.attr('aria-expanded', String(shouldOpen));
if(panel){
panel.hidden=isFooterMobile() ? !shouldOpen:false;
}}
function syncFooterAccordions(){
accordionItems.each(function(){
setFooterAccordionState($(this), false);
});
}
accordionButtons.on('click', function(){
const $item=$(this).parent();
const willOpen = !$item.hasClass('active');
accordionItems.not($item).each(function(){
setFooterAccordionState($(this), false);
});
setFooterAccordionState($item, willOpen);
});
syncFooterAccordions();
$(window).on('resize', syncFooterAccordions);
function initializeSlider(sliderContainerSelector){
const sliderContainer=$(sliderContainerSelector);
if(!sliderContainer.length){
return null;
}
const slider=sliderContainer.find('.slider_card_price');
const slides=slider.find('.slide_card_price');
if(!slider.length||!slides.length){
return null;
}
const prevButton=sliderContainer.find('.prev-button');
const nextButton=sliderContainer.find('.next-button');
const progressBar=sliderContainer.find('.progress-bar');
const slideCount=sliderContainer.find('.slide-count');
let visibleSlides=4;
const slideGap=25;
let slideCountTotal=slides.length;
let currentIndex=0;
let touchStartX=0;
let touchEndX=0;
function updateSliderParams(){
const containerWidth=sliderContainer.width();
if(containerWidth < 549){
visibleSlides=Math.min(2, slideCountTotal);
}else{
visibleSlides=Math.min(4, slideCountTotal);
}
slides.css('flex', `0 0 ${slideWidth()}px`);
currentIndex=Math.min(currentIndex, Math.max(0, slideCountTotal - visibleSlides));
const translateValue=-slideWidthWithGap() * currentIndex;
slider.css('transform', `translateX(${translateValue}px)`);
updateProgressBar();
}
function slideWidth(){
return sliderContainer.width() / visibleSlides - slideGap;
}
function slideWidthWithGap(){
return slideWidth() + slideGap;
}
function updateProgressBar(){
const maxIndex=Math.max(0, slideCountTotal - visibleSlides);
const progressWidth=maxIndex ? (currentIndex / maxIndex) * 100 + '%':'100%';
progressBar.css('width', progressWidth);
const currentSlideCount=Math.min(slideCountTotal, currentIndex + visibleSlides);
slideCount.find('span').text(currentSlideCount.toString().padStart(2, '0'));
prevButton.toggleClass('no-active', currentIndex===0);
nextButton.toggleClass('no-active', currentIndex===maxIndex);
}
function handleTouchStart(event){
touchStartX=event.touches[0].clientX;
}
function handleTouchEnd(event){
touchEndX=event.changedTouches[0].clientX;
handleSwipe();
}
function handleSwipe(){
const sensitivity=50;
const deltaX=touchEndX - touchStartX;
if(deltaX > sensitivity&&currentIndex > 0){
currentIndex--;
}else if(deltaX < -sensitivity&&currentIndex < Math.max(0, slideCountTotal - visibleSlides)){
currentIndex++;
}
const translateValue=-slideWidthWithGap() * currentIndex;
slider.css('transform', `translateX(${translateValue}px)`);
updateProgressBar();
}
$(window).on('resize', updateSliderParams);
sliderContainer.on('click', '.next-button', function (){
if(currentIndex < Math.max(0, slideCountTotal - visibleSlides)){
currentIndex++;
const translateValue=-slideWidthWithGap() * currentIndex;
slider.css('transform', `translateX(${translateValue}px)`);
updateProgressBar();
}});
sliderContainer.on('click', '.prev-button', function (){
if(currentIndex > 0){
currentIndex--;
const translateValue=-slideWidthWithGap() * currentIndex;
slider.css('transform', `translateX(${translateValue}px)`);
updateProgressBar();
}});
sliderContainer[0].addEventListener('touchstart', handleTouchStart);
sliderContainer[0].addEventListener('touchend', handleTouchEnd);
updateSliderParams();
return {
updateSliderParams: updateSliderParams
};}
const slider1=initializeSlider('.slider-container_card_price');
$('.slider-container_card_price').css('display', 'block');
const slider2=initializeSlider('.slider-container_card_price2');
$('.slider-container_card_price2').css('display', 'none');
$('.tab_check').click(function (){
$('.tab_check.active').removeClass('active');
$(this).addClass('active');
if($(this).index()===0){
$('.slider-container_card_price').css('display', 'block');
$('.slider-container_card_price2').css('display', 'none');
if(slider1){
slider1.updateSliderParams();
}}else{
$('.slider-container_card_price').css('display', 'none');
$('.slider-container_card_price2').css('display', 'block');
if(slider2){
slider2.updateSliderParams();
}}
});
document.addEventListener('DOMContentLoaded', function(){
document.addEventListener('click', function(event){
const metricLink=event.target.closest('[data-metric-goal]');
if(metricLink&&typeof window.ym==='function'){
window.ym(73955662, 'reachGoal', metricLink.dataset.metricGoal);
}});
const cityForm=document.getElementById('city-selection-form');
const citySelect=document.getElementById('sortID');
const cityLabel=document.getElementById('changecity');
if(citySelect){
const savedCity=localStorage.getItem('sortId');
if(savedCity){
citySelect.value=savedCity;
}}
if(cityLabel){
cityLabel.textContent=localStorage.getItem('sortId')||'Не выбран';
}
if(cityForm&&citySelect){
cityForm.addEventListener('submit', function(event){
event.preventDefault();
localStorage.setItem('sortId', citySelect.value);
if(cityLabel){
cityLabel.textContent=citySelect.value||'Не выбран';
}});
}
if(typeof window.intlTelInput==='function'){
const phoneUtilsUrl=window.conariumSettings ? window.conariumSettings.intlTelInputUtilsScript:'';
let phoneUtilsRequested=false;
function loadPhoneUtils(){
if(phoneUtilsRequested||!phoneUtilsUrl||typeof window.intlTelInput.loadUtils!=='function'){
return;
}
phoneUtilsRequested=true;
window.intlTelInput.loadUtils(phoneUtilsUrl);
}
document.querySelectorAll('input[name="your-phone"]').forEach(function(input){
if(input.dataset.intlTelInputInitialized){
return;
}
const errorElement=document.createElement('span');
errorElement.className='phone-error';
input.parentNode.appendChild(errorElement);
const phoneInput=window.intlTelInput(input, {
initialCountry: 'ru',
autoPlaceholder: 'aggressive',
});
input.dataset.intlTelInputInitialized='true';
input.addEventListener('focus', loadPhoneUtils, { once: true });
input.addEventListener('countrychange', loadPhoneUtils, { once: true });
input.addEventListener('blur', function(){
loadPhoneUtils();
if(!window.intlTelInput.utils){
return;
}
const isValid=input.value.trim()===''||phoneInput.isValidNumber();
input.classList.toggle('invalid-phone', !isValid);
errorElement.textContent=isValid ? '':'Неверный номер телефона';
});
input.addEventListener('input', function(){
input.classList.remove('invalid-phone');
errorElement.textContent='';
});
});
}
document.querySelectorAll('input[name="your-name"]').forEach(function(input){
input.setAttribute('aria-label', 'Ваше имя');
input.setAttribute('autocomplete', 'name');
input.setAttribute('aria-required', 'true');
});
document.querySelectorAll('input[name="your-phone"]').forEach(function(input){
input.setAttribute('aria-label', 'Номер телефона');
input.setAttribute('autocomplete', 'tel');
input.setAttribute('inputmode', 'tel');
input.setAttribute('aria-required', 'true');
});
[
{
selector: '.u_have_a_quest',
consentNames: ['acceptance-487'],
hintId: 'faq-consent-hint',
pendingMessage: 'Чтобы отправить заявку, подтвердите согласие на обработку персональных данных.',
readyMessage: 'Согласие подтверждено. Можно отправить заявку.'
},
{
selector: '.return_docs_form--installment',
consentNames: ['consent-personal-data', 'consent-legal-representative'],
hintId: 'installment-consent-hint',
pendingMessage: 'Чтобы отправить заявку, подтвердите оба согласия.',
readyMessage: 'Согласия подтверждены. Можно отправить заявку.'
},
{
selector: '.return_docs_form--refund',
consentNames: ['consent-personal-data'],
showConsentHint: false
}
].forEach(function(config){
document.querySelectorAll(config.selector).forEach(function(form){
const formElement=form.closest('form');
const submitButton=form.querySelector('input[type="submit"]');
const submitContainer=submitButton ? (submitButton.closest('p')||submitButton.parentElement):null;
const consentInputs=config.consentNames.map(function(consentName){
return form.querySelector('input[name="' + consentName + '"]');
}).filter(Boolean);
if(!formElement||!submitButton||!submitContainer||consentInputs.length!==config.consentNames.length){
return;
}
let consentHint=null;
if(config.showConsentHint!==false){
consentHint=form.querySelector('.cf7-consent-hint');
if(!consentHint){
consentHint=document.createElement('p');
consentHint.className='cf7-consent-hint';
consentHint.id=config.hintId;
consentHint.setAttribute('role', 'status');
consentHint.setAttribute('aria-live', 'polite');
submitContainer.before(consentHint);
}
submitButton.setAttribute('aria-describedby', consentHint.id);
}else{
form.querySelectorAll('.cf7-consent-hint').forEach(function(hint){
hint.remove();
});
submitButton.removeAttribute('aria-describedby');
}
const syncConsentState=function(){
const consentsConfirmed=consentInputs.every(function(input){
return input.checked;
});
submitButton.disabled = !consentsConfirmed;
if(consentHint){
consentHint.classList.toggle('is-ready', consentsConfirmed);
consentHint.textContent=consentsConfirmed ? config.readyMessage:config.pendingMessage;
}
consentInputs.forEach(function(input){
input.setAttribute('aria-required', 'true');
});
};
consentInputs.forEach(function(input){
input.addEventListener('change', function(){
syncConsentState();
});
});
formElement.addEventListener('wpcf7reset', function(){
delete formElement.dataset.conariumSubmitAttempted;
window.setTimeout(syncConsentState, 0);
});
formElement.addEventListener('wpcf7mailsent', function(){
delete formElement.dataset.conariumSubmitAttempted;
window.setTimeout(syncConsentState, 0);
});
syncConsentState();
});
});
document.addEventListener('wpcf7mailsent', function(event){
if(typeof window.ym==='function'){
const goals={
1529: 'personal-discount',
257: 'question',
263: 'callback',
};
const goal=goals[event.detail.contactFormId];
if(goal){
window.ym(73955662, 'reachGoal', goal);
}}
if(document.querySelector('.prpnso_form')){
$('.prpnso_form').hide();
$('.download_pnso').css('display', 'flex');
}});
$('#getguide').on('click', function(){
$('.prpnso_form').addClass('fill_form');
window.setTimeout(function(){
$('.prpnso_form').removeClass('fill_form');
}, 5000);
});
$('#get_form_affiliate').on('click', function(){
$('.block_5_affilate_item_form').toggleClass('hide_border');
window.setTimeout(function(){
$('.block_5_affilate_item_form').toggleClass('hide_border');
}, 5000);
});
const $blog=$('.newspage-wrap');
if($blog.length&&window.conariumSettings){
let currentPage=1;
let currentCategory=Number($blog.data('initial-category'))||0;
let currentCategoryLabel=String($blog.data('initial-category-label')||'Все');
let activeRequest=null;
let requestSequence=0;
const $loadMoreButton=$('.blog-more');
const $topicList=$('.ajax_cat_list');
const $resultsStatus=$('#blog-results-status');
const loadMoreLabel=$loadMoreButton.text().trim();
let lastSuccessfulState={
category: currentCategory,
categoryLabel: currentCategoryLabel,
html: $blog.html(),
page: currentPage,
hasMore: $loadMoreButton.is(':visible'),
};
function createSkeletonCards(count){
return Array.from({ length: count }, function(){
return [
'<div class="blog-skeleton" aria-hidden="true">',
'<div class="blog-skeleton__image"></div>',
'<div class="blog-skeleton__body">',
'<span class="blog-skeleton__line blog-skeleton__line--short"></span>',
'<span class="blog-skeleton__line"></span>',
'<span class="blog-skeleton__line blog-skeleton__line--medium"></span>',
'</div>',
'</div>',
].join('');
}).join('');
}
function setActiveCategory(categoryId){
const $categoryButtons=$topicList.find('[data-category-id]');
const $activeButton=$categoryButtons.filter('[data-category-id="' + categoryId + '"]');
$categoryButtons.removeClass('active').attr('aria-pressed', 'false');
$activeButton.addClass('active').attr('aria-pressed', 'true');
const topicList=$topicList.get(0);
const activeButton=$activeButton.get(0);
if(!topicList||!activeButton){
return;
}
const visibleLeft=topicList.scrollLeft;
const visibleRight=visibleLeft + topicList.clientWidth;
const listBox=topicList.getBoundingClientRect();
const buttonBox=activeButton.getBoundingClientRect();
const buttonLeft=visibleLeft + buttonBox.left - listBox.left;
const buttonRight=buttonLeft + activeButton.offsetWidth;
const edgePadding=topicList.scrollWidth > topicList.clientWidth ? 40:0;
if(buttonLeft < visibleLeft||buttonRight > visibleRight - edgePadding){
const targetLeft=Math.max(0,
Math.min(buttonLeft - 8, buttonRight - topicList.clientWidth + edgePadding)
);
topicList.scrollTo({ left: targetLeft, behavior: 'auto' });
}}
function setResultsStatus(message, isError){
$resultsStatus.text(message).toggleClass('is-error', Boolean(isError));
}
function setLoadingState(isLoading){
$blog.attr('aria-busy', isLoading ? 'true':'false').toggleClass('is-loading', isLoading);
$loadMoreButton
.prop('disabled', isLoading)
.attr('aria-busy', isLoading ? 'true':'false')
.text(isLoading ? 'Загружаем материалы…':loadMoreLabel);
}
function updateTopicUrl(categoryId){
if(!window.history||!window.history.replaceState||!window.URL){
return;
}
const url=new URL(window.location.href);
url.searchParams.set('topic', categoryId);
window.history.replaceState({}, '', url.toString());
}
function restoreLastSuccessfulState(){
currentCategory=lastSuccessfulState.category;
currentCategoryLabel=lastSuccessfulState.categoryLabel;
currentPage=lastSuccessfulState.page;
$blog.html(lastSuccessfulState.html);
$loadMoreButton.toggle(lastSuccessfulState.hasMore);
setActiveCategory(currentCategory);
}
function renderPosts(categoryId, page, categoryLabel){
const requestId=++requestSequence;
const isFirstPage=page===1;
if(activeRequest){
activeRequest.abort();
}
if(isFirstPage){
$blog.html(createSkeletonCards(6));
}else{
$blog.append(createSkeletonCards(3));
}
setLoadingState(true);
setResultsStatus('Загружаем материалы: ' + categoryLabel + '…');
activeRequest=$.ajax({
url: window.conariumSettings.ajaxUrl,
method: 'POST',
dataType: 'json',
data: {
action: 'more_post_ajax',
category: categoryId,
paged: page,
nonce: window.conariumSettings.loadMorePostsNonce,
},
}).done(function(response){
if(requestId!==requestSequence){
return;
}
if(!response.success||!response.data){
restoreLastSuccessfulState();
setResultsStatus('Не удалось обновить список. Показаны материалы: ' + currentCategoryLabel + '.', true);
return;
}
if(isFirstPage){
$blog.html(response.data.html);
}else{
$blog.find('.blog-skeleton').remove();
$blog.append(response.data.html);
}
currentCategory=categoryId;
currentCategoryLabel=categoryLabel;
currentPage=page;
lastSuccessfulState={
category: currentCategory,
categoryLabel: currentCategoryLabel,
html: $blog.html(),
page: currentPage,
hasMore: Boolean(response.data.has_more),
};
$loadMoreButton.toggle(lastSuccessfulState.hasMore);
setActiveCategory(currentCategory);
setResultsStatus('Показаны материалы: ' + currentCategoryLabel + '.');
updateTopicUrl(currentCategory);
}).fail(function(_, textStatus){
if(textStatus==='abort'||requestId!==requestSequence){
return;
}
restoreLastSuccessfulState();
setResultsStatus('Не удалось обновить список. Показаны материалы: ' + currentCategoryLabel + '.', true);
}).always(function(){
if(requestId!==requestSequence){
return;
}
activeRequest=null;
setLoadingState(false);
});
}
$topicList.on('click', '[data-category-id]', function(){
const categoryId=Number(this.dataset.categoryId)||0;
const categoryLabel=String(this.dataset.categoryLabel||$(this).text().trim());
if(!activeRequest&&categoryId===currentCategory){
return;
}
setActiveCategory(categoryId);
renderPosts(categoryId, 1, categoryLabel);
});
$loadMoreButton.on('click', function(event){
event.preventDefault();
if(activeRequest){
return;
}
renderPosts(currentCategory, currentPage + 1, currentCategoryLabel);
});
}});