document.addEventListener('DOMContentLoaded', function (){
const modal=document.getElementById('cookiesPopup');
if(modal){
if(!modal.hasAttribute('tabindex')){
modal.setAttribute('tabindex', '-1');
}
modal.removeAttribute('hidden');
modal.focus();
const focusableSelectors =
'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
const focusableElements=modal.querySelectorAll(focusableSelectors);
if(focusableElements.length > 0){
const firstFocusable=focusableElements[0];
const lastFocusable=focusableElements[focusableElements.length - 1];
modal.addEventListener('keydown', function (e){
const isTab=e.key==='Tab';
const isEsc=e.key==='Escape';
if(isTab){
if(e.shiftKey){
if(document.activeElement===firstFocusable){
e.preventDefault();
lastFocusable.focus();
}}else{
if(document.activeElement===lastFocusable){
e.preventDefault();
firstFocusable.focus();
}}
}
if(isEsc){
modal.setAttribute('hidden', 'true');
}});
}}
const toggleBtn=document.getElementById('toggle-slider');
if(toggleBtn&&window.jQuery&&jQuery.fn&&typeof jQuery.fn.slick==='function'){
const slider=jQuery('#slick-slider');
let paused=false;
toggleBtn.addEventListener('click', function (){
paused = !paused;
if(paused){
slider.slick('slickPause');
toggleBtn.setAttribute('aria-pressed', 'true');
toggleBtn.setAttribute('aria-label', 'Wznów automatyczne przewijanie slajdów');
toggleBtn.innerHTML='▶ Wznów animację';
}else{
slider.slick('slickPlay');
toggleBtn.setAttribute('aria-pressed', 'false');
toggleBtn.setAttribute('aria-label', 'Zatrzymaj automatyczne przewijanie slajdów');
toggleBtn.innerHTML='⏸ Zatrzymaj animację';
}});
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches){
slider.slick('slickPause');
}}
const skipLink=document.querySelector('.skip-link');
if(skipLink){
skipLink.addEventListener('click', function (){
const target=document.getElementById('main-content');
if(target){
if(!target.hasAttribute('tabindex')) target.setAttribute('tabindex', '-1');
target.focus();
}});
}});
(function waitForRecaptchaField(){
const FIELD_ID='g-recaptcha-response';
const LABEL_TEXT='Potwierdź, że nie jesteś robotem';
function enhanceRecaptchaField(field){
field.setAttribute('aria-hidden', 'true');
const existingLabel=document.querySelector('label[for="' + FIELD_ID + '"]');
if(!existingLabel&&field.parentNode){
const label=document.createElement('label');
label.setAttribute('for', FIELD_ID);
label.className='visually-hidden';
label.textContent=LABEL_TEXT;
field.parentNode.insertBefore(label, field);
}}
function tryInsert(){
const field=document.getElementById(FIELD_ID);
if(field){
enhanceRecaptchaField(field);
return true;
}
return false;
}
if(!tryInsert()){
let attempts=0;
const maxAttempts=25;
const interval=setInterval(function (){
if(tryInsert()||++attempts >=maxAttempts){
clearInterval(interval);
}}, 200);
}})();