(function (){
'use strict';
var settings=window.conariumCookieConsentSettings||{};
var banner=document.getElementById('conarium-cookie-consent');
var consentName='conarium_cookie_consent';
var consentStorageKey='conarium_cookie_consent';
var consentLifetime=31536000;
var analyticsConsent='analytics';
var necessaryConsent='necessary';
var optionalServicesLoaded=false;
if(!banner){
return;
}
function getCookie(name){
var prefix=name + '=';
var values=document.cookie ? document.cookie.split('; '):[];
for (var index=0; index < values.length; index +=1){
if(values[index].indexOf(prefix)===0){
return decodeURIComponent(values[index].slice(prefix.length));
}}
return '';
}
function getStoredConsent(){
var cookieValue=getCookie(consentName);
if(cookieValue===analyticsConsent||cookieValue===necessaryConsent){
return cookieValue;
}
try {
var storageValue=window.localStorage.getItem(consentStorageKey);
return storageValue===analyticsConsent||storageValue===necessaryConsent ? storageValue:'';
} catch (error){
return '';
}}
function storeConsent(value){
var secure=window.location.protocol==='https:' ? '; Secure':'';
document.cookie=consentName + '=' + encodeURIComponent(value) + '; path=/; max-age=' + consentLifetime + '; SameSite=Lax' + secure;
try {
window.localStorage.setItem(consentStorageKey, value);
} catch (error){
}}
function loadScript(source, onLoad){
var existing=document.querySelector('script[data-consent-source="' + source + '"]');
if(existing){
if(existing.dataset.loaded==='true'){
onLoad();
}else{
existing.addEventListener('load', onLoad, { once: true });
}
return;
}
var script=document.createElement('script');
script.async=true;
script.src=source;
script.dataset.consentSource=source;
script.addEventListener('load', function (){
script.dataset.loaded='true';
onLoad();
}, { once: true });
document.head.appendChild(script);
}
function loadMetrikaAfterFirstRender(){
var load=function (){
window.setTimeout(function (){
loadScript(settings.metrikaScriptUrl, function (){});
}, 2500);
};
if(document.readyState==='complete'){
load();
return;
}
window.addEventListener('load', load, { once: true });
}
function startMetrika(){
if(!settings.metrikaId||!settings.metrikaScriptUrl||window.__conariumMetrikaInitialized){
return;
}
window.ym=window.ym||function (){
(window.ym.a=window.ym.a||[]).push(arguments);
};
window.ym.l=Date.now();
window.ym(settings.metrikaId, 'init', {
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: true
});
window.__conariumMetrikaInitialized=true;
loadMetrikaAfterFirstRender();
}
function clearMetrikaCookies(){
var secure=window.location.protocol==='https:' ? '; Secure':'';
var cookies=document.cookie ? document.cookie.split('; '):[];
cookies.forEach(function (item){
var name=item.split('=')[0];
if(name.indexOf('_ym_')===0){
document.cookie=name + '=; path=/; max-age=0; SameSite=Lax' + secure;
}});
}
function startYandexShare(){
if(!settings.yandexShareUrl||!document.querySelector('.ya-share2')){
return;
}
loadScript(settings.yandexShareUrl, function (){});
}
function enableOptionalServices(){
if(optionalServicesLoaded){
return;
}
optionalServicesLoaded=true;
document.documentElement.dataset.cookieConsent=analyticsConsent;
startMetrika();
startYandexShare();
document.dispatchEvent(new CustomEvent('conarium:analytics-consent'));
}
function showBanner(){
banner.hidden=false;
}
function hideBanner(){
banner.hidden=true;
}
function setConsent(value){
var previousConsent=getStoredConsent();
storeConsent(value);
hideBanner();
if(value===analyticsConsent){
enableOptionalServices();
return;
}
document.documentElement.dataset.cookieConsent=necessaryConsent;
if(previousConsent===analyticsConsent){
if(typeof window.ym==='function'&&settings.metrikaId){
window.ym(settings.metrikaId, 'destruct');
}
clearMetrikaCookies();
window.location.reload();
}}
banner.addEventListener('click', function (event){
var button=event.target.closest('[data-cookie-consent-action]');
if(!button){
return;
}
setConsent(button.dataset.cookieConsentAction==='accept' ? analyticsConsent:necessaryConsent);
});
Array.prototype.forEach.call(document.querySelectorAll('[data-cookie-consent-settings]'), function (trigger){
trigger.addEventListener('click', function (){
showBanner();
var primaryButton=banner.querySelector('[data-cookie-consent-action="accept"]');
if(primaryButton){
primaryButton.focus();
}});
});
window.conariumCookieConsent={
hasAnalyticsConsent: function (){
return getStoredConsent()===analyticsConsent;
},
openPreferences: showBanner
};
if(getStoredConsent()===analyticsConsent){
hideBanner();
enableOptionalServices();
}else if(getStoredConsent()===necessaryConsent){
hideBanner();
document.documentElement.dataset.cookieConsent=necessaryConsent;
}else{
showBanner();
}}());