200 lines
8.9 KiB
JavaScript
200 lines
8.9 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
/**
|
|
* ===================================================================
|
|
* 1. OSNOVNA FUNKCIONALNOST MOBILNE NAVIGACIJE (Robustna različica)
|
|
* ===================================================================
|
|
*/
|
|
|
|
// === MOBILNI MENI: Robusten toggle na <html> ===
|
|
try {
|
|
const icon = document.querySelector('.mobile-menu-icon');
|
|
const root = document.documentElement; // Ciljamo <html>, da se izognemo konfliktom na <body>
|
|
|
|
if (!icon) {
|
|
console.error('Mobile menu icon not found.');
|
|
} else {
|
|
icon.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation(); // Preprečimo "bubbling" dogodka, ki bi lahko takoj zaprl meni
|
|
root.classList.toggle('nav-open');
|
|
});
|
|
|
|
// Zapri meni ob kliku izven panela ali ikone
|
|
document.addEventListener('click', (e) => {
|
|
if (root.classList.contains('nav-open') && !e.target.closest('.mobile-nav-panel') && !e.target.closest('.mobile-menu-icon')) {
|
|
root.classList.remove('nav-open');
|
|
}
|
|
});
|
|
|
|
// Zapri meni s tipko Escape
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape') {
|
|
root.classList.remove('nav-open');
|
|
}
|
|
});
|
|
}
|
|
} catch (err) {
|
|
console.error('Error in Mobile Menu Toggle:', err);
|
|
}
|
|
|
|
// --- Mobilni Accordion podmeni (ostane nespremenjen) ---
|
|
try {
|
|
const mobileNav = document.querySelector('.mobile-nav-panel .mobile-nav');
|
|
if (mobileNav) {
|
|
const menuItemsWithChildren = mobileNav.querySelectorAll('.menu-item-has-children');
|
|
|
|
menuItemsWithChildren.forEach(item => {
|
|
const link = item.querySelector('a');
|
|
if (link) {
|
|
link.addEventListener('click', (event) => {
|
|
// Prepreči privzeto dejanje samo za glavne povezave, ki imajo podmeni
|
|
if (event.currentTarget.parentElement.classList.contains('menu-item-has-children')) {
|
|
event.preventDefault();
|
|
}
|
|
|
|
const parentLi = event.currentTarget.parentElement;
|
|
|
|
// Zapri ostale odprte podmenije (efekt harmonike)
|
|
menuItemsWithChildren.forEach(otherItem => {
|
|
if (otherItem !== parentLi && otherItem.classList.contains('open')) {
|
|
otherItem.classList.remove('open');
|
|
}
|
|
});
|
|
|
|
// Preklopi stanje trenutnega podmenija
|
|
parentLi.classList.toggle('open');
|
|
});
|
|
}
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Error in Mobile Accordion Menu:', error);
|
|
}
|
|
|
|
|
|
/**
|
|
* ===================================================================
|
|
* 2. DODATNE FUNKCIONALNOSTI (Jezik, FAQ, itd.)
|
|
* Te skripte so ločene, da morebitne napake ne vplivajo na meni.
|
|
* ===================================================================
|
|
*/
|
|
|
|
// --- Preklopnik jezika (Language Switcher) ---
|
|
try {
|
|
const languageSelectors = document.querySelectorAll('.language-selector');
|
|
if (languageSelectors.length > 0) {
|
|
languageSelectors.forEach(selector => {
|
|
const currentLang = selector.querySelector('.current-lang');
|
|
if (currentLang) {
|
|
currentLang.addEventListener('click', (event) => {
|
|
event.stopPropagation();
|
|
const isActive = selector.classList.contains('active');
|
|
languageSelectors.forEach(s => s.classList.remove('active')); // Zapri vse
|
|
if (!isActive) {
|
|
selector.classList.add('active'); // Odpri samo trenutnega
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Globalni listenerji za zapiranje
|
|
window.addEventListener('click', () => {
|
|
languageSelectors.forEach(s => s.classList.remove('active'));
|
|
});
|
|
window.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape') {
|
|
languageSelectors.forEach(s => s.classList.remove('active'));
|
|
}
|
|
});
|
|
|
|
// Dinamično generiranje URL-jev
|
|
const path = window.location.pathname;
|
|
const pathParts = path.split('/').filter(Boolean);
|
|
const validLangs = ['en', 'si', 'mk'];
|
|
let currentLangCode = validLangs[0]; // Privzeto na 'en', če ni najden
|
|
let relativePathAfterLang = path;
|
|
|
|
for (const lang of validLangs) {
|
|
if (pathParts.length > 0 && pathParts[0] === lang) {
|
|
currentLangCode = lang;
|
|
relativePathAfterLang = '/' + pathParts.slice(1).join('/');
|
|
break;
|
|
}
|
|
}
|
|
|
|
languageSelectors.forEach(selector => {
|
|
const langLinks = selector.querySelectorAll('.lang-dropdown a[data-lang]');
|
|
langLinks.forEach(link => {
|
|
const targetLang = link.getAttribute('data-lang');
|
|
// Zgradi novo pot relativno glede na korensko mapo
|
|
const newUrl = `/${targetLang}${relativePathAfterLang === '/' ? '' : relativePathAfterLang}`;
|
|
link.setAttribute('href', newUrl);
|
|
});
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Error in Language Switcher:', error);
|
|
}
|
|
|
|
// --- FAQ Accordion ---
|
|
try {
|
|
const faqItems = document.querySelectorAll('.faq-item');
|
|
if (faqItems.length > 0) {
|
|
faqItems.forEach(item => {
|
|
const header = item.querySelector('h3');
|
|
if (header) {
|
|
header.addEventListener('click', () => {
|
|
const content = item.querySelector('p');
|
|
if (content) {
|
|
if (content.style.display === "none" || content.style.display === "") {
|
|
content.style.display = "block";
|
|
} else {
|
|
content.style.display = "none";
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Error in FAQ Accordion:', error);
|
|
}
|
|
|
|
// --- Activities Tab ---
|
|
try {
|
|
const activityNavItems = document.querySelectorAll('.activities-nav li');
|
|
const activityDetailsText = document.querySelector('.activity-details p');
|
|
|
|
if (activityNavItems.length > 0 && activityDetailsText) {
|
|
const activitiesData = {
|
|
'Študentsko predstavništvo': { text: 'Vsebina za študentsko predstavništvo...'},
|
|
'Izobraževanje in kultura': { text: 'Vsebina za izobraževanje in kulturo...'},
|
|
'Zabava in druženje': { text: 'Vsebina za zabavo in druženje...'},
|
|
'Študentska podpora': { text: 'Vsebina za študentsko podoro...'},
|
|
'Student representation': { text: 'Content for student representation...'},
|
|
'Education and culture': { text: 'Content for education and culture...'},
|
|
'Entertainment and socializing': { text: 'Content for entertainment and socializing...'},
|
|
'Student support': { text: 'Content for student support...'},
|
|
'Студентско претставување': { text: 'Содржина за студентско претставување...'},
|
|
'Образование и култура': { text: 'Содржина за образование и култура...'},
|
|
'Забава и дружење': { text: 'Содржина за забава и дружење...'},
|
|
'Студентска поддршка': { text: 'Содржина за студентска поддршка...'}
|
|
};
|
|
|
|
activityNavItems.forEach(item => {
|
|
item.addEventListener('click', () => {
|
|
activityNavItems.forEach(navItem => navItem.classList.remove('active'));
|
|
item.classList.add('active');
|
|
|
|
const activityName = item.textContent.trim();
|
|
if (activitiesData[activityName]) {
|
|
activityDetailsText.textContent = activitiesData[activityName].text;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Error in Activities Tab:', error);
|
|
}
|
|
}); |