This commit is contained in:
1 parent
544791f37e
commit
6ed8073b76
25 files changed
+7674
-1861
No files matched your search
@@ -1,141 +1,185 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
// --- Mobile Menu Toggle ---
|
||||
const mobileMenuIcon = document.querySelector('.mobile-menu-icon');
|
||||
const body = document.querySelector('body');
|
||||
/**
|
||||
* ===================================================================
|
||||
* 1. OSNOVNA FUNKCIONALNOST MOBILNE NAVIGACIJE
|
||||
* Ta koda je ključna za delovanje mobilnega menija.
|
||||
* ===================================================================
|
||||
*/
|
||||
|
||||
if (mobileMenuIcon && body) {
|
||||
mobileMenuIcon.addEventListener('click', () => {
|
||||
// Preklopi razred 'nav-open' na body elementu za prikaz/skrivanje menija
|
||||
body.classList.toggle('nav-open');
|
||||
});
|
||||
// --- Odpiranje in zapiranje glavnega mobilnega panela ---
|
||||
try {
|
||||
const mobileMenuIcon = document.querySelector('.mobile-menu-icon');
|
||||
const body = document.querySelector('body');
|
||||
|
||||
if (mobileMenuIcon && body) {
|
||||
mobileMenuIcon.addEventListener('click', () => {
|
||||
body.classList.toggle('nav-open');
|
||||
});
|
||||
} else {
|
||||
console.error('Mobile menu icon or body not found.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in Mobile Menu Toggle:', error);
|
||||
}
|
||||
|
||||
// --- Language Switcher ---
|
||||
const languageSelectors = document.querySelectorAll('.language-selector');
|
||||
// --- Mobilni Accordion podmeni ---
|
||||
try {
|
||||
const mobileNav = document.querySelector('.mobile-nav-panel .mobile-nav');
|
||||
if (mobileNav) {
|
||||
const menuItemsWithChildren = mobileNav.querySelectorAll('.menu-item-has-children');
|
||||
|
||||
if (languageSelectors.length > 0) {
|
||||
languageSelectors.forEach(selector => {
|
||||
const currentLang = selector.querySelector('.current-lang');
|
||||
|
||||
if (currentLang) {
|
||||
currentLang.addEventListener('click', (event) => {
|
||||
// Prepreči, da bi klik na sprožilec takoj zaprl meni (zaradi globalnega listenerja)
|
||||
event.stopPropagation();
|
||||
|
||||
// Preklopi .active razred na trenutnem menjalniku
|
||||
selector.classList.toggle('active');
|
||||
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();
|
||||
}
|
||||
|
||||
// Zapri vse ostale odprte menjalnike jezikov
|
||||
languageSelectors.forEach(otherSelector => {
|
||||
if (otherSelector !== selector) {
|
||||
otherSelector.classList.remove('active');
|
||||
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 listener za zapiranje menija ob kliku izven njega
|
||||
window.addEventListener('click', () => {
|
||||
// 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 => {
|
||||
selector.classList.remove('active');
|
||||
});
|
||||
});
|
||||
|
||||
// Globalni listener za zapiranje menija s tipko Escape
|
||||
window.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Escape') {
|
||||
languageSelectors.forEach(selector => {
|
||||
selector.classList.remove('active');
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Logika za dinamično generiranje URL-jev ostaja enaka
|
||||
// Ta del poskrbi, da povezave v meniju vodijo na pravo jezikovno različico strani
|
||||
const path = window.location.pathname;
|
||||
const pathParts = path.split('/').filter(Boolean);
|
||||
|
||||
// Predpostavka: prvi del poti je vedno jezikovna koda
|
||||
const currentLangCode = pathParts[0] || 'si'; // Privzeto na 'si', če ni določeno
|
||||
const relativePath = path.substring(path.indexOf(currentLangCode) + currentLangCode.length);
|
||||
|
||||
languageSelectors.forEach(selector => {
|
||||
const langLinks = selector.querySelectorAll('.lang-dropdown a[data-lang]');
|
||||
langLinks.forEach(link => {
|
||||
const targetLang = link.getAttribute('data-lang');
|
||||
const newUrl = `/${targetLang}${relativePath}`;
|
||||
link.setAttribute('href', newUrl);
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in Language Switcher:', error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --- FAQ Accordion ---
|
||||
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) {
|
||||
// Preprost preklop prikaza. Za napredno harmoniko bi uporabili razrede.
|
||||
if (content.style.display === "none" || content.style.display === "") {
|
||||
content.style.display = "block";
|
||||
} else {
|
||||
content.style.display = "none";
|
||||
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 ---
|
||||
const activityNavItems = document.querySelectorAll('.activities-nav li');
|
||||
const activityDetailsText = document.querySelector('.activity-details p');
|
||||
const activityDetailsImage = document.querySelector('.activity-details img');
|
||||
|
||||
// Placeholder vsebina za različne aktivnosti
|
||||
const activitiesData = {
|
||||
// Slovenska vsebina
|
||||
'Š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...'},
|
||||
// Angleška vsebina
|
||||
'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...'},
|
||||
// Makedonska vsebina
|
||||
'Студентско претставување': { text: 'Содржина за студентско претставување...'},
|
||||
'Образование и култура': { text: 'Содржина за образование и култура...'},
|
||||
'Забава и дружење': { text: 'Содржина за забава и дружење...'},
|
||||
'Студентска поддршка': { text: 'Содржина за студентска поддршка...'}
|
||||
};
|
||||
|
||||
if (activityNavItems.length > 0 && activityDetailsText) {
|
||||
activityNavItems.forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
// Odstrani .active razred z vseh elementov
|
||||
activityNavItems.forEach(navItem => navItem.classList.remove('active'));
|
||||
// Dodaj .active razred na kliknjen element
|
||||
item.classList.add('active');
|
||||
|
||||
// Posodobi vsebino glede na besedilo kliknjenega elementa
|
||||
const activityName = item.textContent.trim();
|
||||
if (activitiesData[activityName]) {
|
||||
activityDetailsText.textContent = activitiesData[activityName].text;
|
||||
// Tukaj bi lahko posodobili tudi sliko, če je potrebno
|
||||
// if (activityDetailsImage) {
|
||||
// activityDetailsImage.src = activitiesData[activityName].image;
|
||||
// }
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user