This commit is contained in:
1 parent
c1094898b7
commit
37b72526d8
51 files changed
+4294
-2776
No files matched your search
@@ -2,32 +2,30 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* 1. OSNOVNA FUNKCIONALNOST MOBILNE NAVIGACIJE (Robustna različica)
|
||||
* 1. OSNOVNA FUNKCIONALNOST MOBILNE NAVIGACIJE
|
||||
* ===================================================================
|
||||
*/
|
||||
|
||||
// === MOBILNI MENI: Robusten toggle na <html> ===
|
||||
// === MOBILNI MENI: Preklop vidnosti menija ===
|
||||
try {
|
||||
const icon = document.querySelector('.mobile-menu-icon');
|
||||
const root = document.documentElement; // Ciljamo <html>, da se izognemo konfliktom na <body>
|
||||
const root = document.documentElement;
|
||||
|
||||
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
|
||||
e.stopPropagation();
|
||||
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');
|
||||
@@ -38,7 +36,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
console.error('Error in Mobile Menu Toggle:', err);
|
||||
}
|
||||
|
||||
// --- Mobilni Accordion podmeni (ostane nespremenjen) ---
|
||||
// --- Mobilni Accordion podmeni ---
|
||||
try {
|
||||
const mobileNav = document.querySelector('.mobile-nav-panel .mobile-nav');
|
||||
if (mobileNav) {
|
||||
@@ -48,21 +46,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
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');
|
||||
});
|
||||
}
|
||||
@@ -75,88 +70,135 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* 2. DODATNE FUNKCIONALNOSTI (Jezik, FAQ, itd.)
|
||||
* Te skripte so ločene, da morebitne napake ne vplivajo na meni.
|
||||
* 2. IZBOLJŠAVE UPORABNIŠKE IZKUŠNJE (UX/UI)
|
||||
* ===================================================================
|
||||
*/
|
||||
|
||||
// --- Preklopnik jezika (Language Switcher) ---
|
||||
try {
|
||||
const languageSelectors = document.querySelectorAll('.language-selector');
|
||||
if (languageSelectors.length > 0) {
|
||||
languageSelectors.forEach(selector => {
|
||||
// --- Funkcija za poudarjanje aktivne povezave v navigaciji ---
|
||||
function highlightActiveLink() {
|
||||
try {
|
||||
const currentPath = window.location.pathname;
|
||||
const navLinks = document.querySelectorAll('.navigation a');
|
||||
let bestMatch = null;
|
||||
let longestMatch = 0;
|
||||
|
||||
navLinks.forEach(link => {
|
||||
if (link.closest('.dropdown-menu')) return;
|
||||
|
||||
const linkPath = new URL(link.href, window.location.origin).pathname;
|
||||
|
||||
if (currentPath.startsWith(linkPath) && linkPath.length > longestMatch) {
|
||||
longestMatch = linkPath.length;
|
||||
bestMatch = link;
|
||||
}
|
||||
});
|
||||
|
||||
if (bestMatch) {
|
||||
const parentMenuItem = bestMatch.closest('.menu-item');
|
||||
if (parentMenuItem) {
|
||||
parentMenuItem.classList.add('active-page');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error highlighting active link:", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --- Funkcionalnost za preklopnik jezika (Desktop Dropdown + Mobile Modal) ---
|
||||
function setupLanguageSwitcher() {
|
||||
try {
|
||||
// 1. POPRAVLJENA Logika za dinamično generiranje URL-jev
|
||||
const path = window.location.pathname;
|
||||
const pathParts = path.split('/').filter(Boolean);
|
||||
const validLangs = ['en', 'si', 'mk'];
|
||||
let pathWithoutLang = '/';
|
||||
|
||||
if (pathParts.length > 0 && validLangs.includes(pathParts[0])) {
|
||||
// Sestavi pot iz delov, ki sledijo jezikovni kodi
|
||||
pathWithoutLang = '/' + pathParts.slice(1).join('/');
|
||||
// Če se je originalna pot končala s '/', jo dodaj nazaj (za mape)
|
||||
if (path.endsWith('/') && pathWithoutLang !== '/') {
|
||||
pathWithoutLang += '/';
|
||||
}
|
||||
} else {
|
||||
pathWithoutLang = path;
|
||||
}
|
||||
|
||||
document.querySelectorAll('a[data-lang]').forEach(link => {
|
||||
const targetLang = link.getAttribute('data-lang');
|
||||
// Združi novo jezikovno kodo in preostanek poti
|
||||
const newUrl = `/${targetLang}${pathWithoutLang}`;
|
||||
// Zamenjaj morebitne dvojne poševnice z eno samo, razen na začetku
|
||||
link.setAttribute('href', newUrl.replace(/\/{2,}/g, '/'));
|
||||
});
|
||||
|
||||
// 2. POPRAVLJENA Logika za NAMIZNI dropdown
|
||||
// Uporablja bolj specifičen selektor, ki se ujema z novo HTML strukturo
|
||||
const desktopSelectors = document.querySelectorAll('.header-right-wrapper .language-selector');
|
||||
desktopSelectors.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
|
||||
document.querySelectorAll('.language-selector.active').forEach(s => s.classList.remove('active'));
|
||||
if (!isActive) {
|
||||
selector.classList.add('active'); // Odpri samo trenutnega
|
||||
selector.classList.add('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
});
|
||||
window.addEventListener('click', () => {
|
||||
desktopSelectors.forEach(s => s.classList.remove('active'));
|
||||
});
|
||||
|
||||
// 3. Logika za MOBILNO modalno okno (ostaja enaka, vendar bo zdaj delovala pravilno)
|
||||
const mobileLangButton = document.getElementById('mobile-lang-trigger');
|
||||
const languageModal = document.getElementById('language-modal-overlay');
|
||||
const closeModalButton = document.getElementById('language-modal-close');
|
||||
|
||||
if (mobileLangButton && languageModal && closeModalButton) {
|
||||
mobileLangButton.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
languageModal.classList.add('active');
|
||||
});
|
||||
|
||||
const closeModal = () => {
|
||||
languageModal.classList.remove('active');
|
||||
};
|
||||
|
||||
closeModalButton.addEventListener('click', closeModal);
|
||||
languageModal.addEventListener('click', (e) => {
|
||||
if (e.target === languageModal) closeModal();
|
||||
});
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && languageModal.classList.contains('active')) closeModal();
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error in Language Switcher setup:', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in Language Switcher:', error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* 3. OSTALE FUNKCIONALNOSTI (FAQ, ACTIVITIES, ITD.)
|
||||
* ===================================================================
|
||||
*/
|
||||
|
||||
// --- 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";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
document.querySelectorAll('.faq-item h3').forEach(header => {
|
||||
header.addEventListener('click', () => {
|
||||
const faqItem = header.parentElement;
|
||||
faqItem.classList.toggle('open');
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error in FAQ Accordion:', error);
|
||||
}
|
||||
@@ -197,4 +239,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
} catch (error) {
|
||||
console.error('Error in Activities Tab:', error);
|
||||
}
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* 4. ZAGON FUNKCIJ PO NALOŽITVI STRANI
|
||||
* ===================================================================
|
||||
*/
|
||||
highlightActiveLink();
|
||||
setupLanguageSwitcher();
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user