Posodobljeni meniji pri clankih
Deploy to Production on Develop Push / deploy (push) Successful in 1m15s
Deploy to Production on Develop Push / deploy (push) Successful in 1m15s
This commit is contained in:
1 parent
90055985fd
commit
28c097a959
9 files changed
+3053
-2537
No files matched your search
@@ -247,10 +247,114 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
} catch(error) {
|
||||
console.error('Error in Mission/Vision interaction setup:', error);
|
||||
}
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* 5. SCROLLSPY IN PROGRESS BAR ZA STRANI ČLANKOV (POSODOBLJENO)
|
||||
* ===================================================================
|
||||
*/
|
||||
try {
|
||||
const articlePage = document.querySelector('.article-page');
|
||||
if (articlePage) {
|
||||
const scrollspyNav = document.querySelector('.scrollspy-nav');
|
||||
const mobileHeader = document.querySelector('.mobile-article-header');
|
||||
const mobileTitle = document.getElementById('mobile-article-title');
|
||||
const mobileDropdown = document.querySelector('.mobile-scrollspy-dropdown');
|
||||
const mobileLinksContainer = document.getElementById('mobile-scrollspy-links');
|
||||
const progressBar = document.querySelector('.progress-bar');
|
||||
|
||||
const headings = Array.from(articlePage.querySelectorAll('.article-body h2'));
|
||||
const desktopNavLinks = scrollspyNav ? Array.from(scrollspyNav.querySelectorAll('a')) : [];
|
||||
|
||||
// --- Dinamično ustvarjanje mobilnega spustnega seznama ---
|
||||
if (headings.length > 0 && mobileLinksContainer) {
|
||||
headings.forEach(heading => {
|
||||
const listItem = document.createElement('li');
|
||||
const link = document.createElement('a');
|
||||
link.href = `#${heading.id}`;
|
||||
link.textContent = heading.textContent;
|
||||
listItem.appendChild(link);
|
||||
mobileLinksContainer.appendChild(listItem);
|
||||
});
|
||||
}
|
||||
|
||||
// --- Logika za odpiranje/zapiranje mobilnega spustnega seznama ---
|
||||
if (mobileHeader && mobileDropdown) {
|
||||
mobileHeader.addEventListener('click', (e) => {
|
||||
// Preprečimo, da se meni zapre, če kliknemo na povezavo znotraj njega
|
||||
if (!e.target.closest('a')) {
|
||||
mobileHeader.classList.toggle('open');
|
||||
mobileDropdown.classList.toggle('open');
|
||||
}
|
||||
});
|
||||
|
||||
// Dodamo dogodek za zapiranje menija ob kliku na povezavo
|
||||
mobileDropdown.querySelectorAll('a').forEach(link => {
|
||||
link.addEventListener('click', () => {
|
||||
mobileHeader.classList.remove('open');
|
||||
mobileDropdown.classList.remove('open');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --- Logika za Progress Bar ---
|
||||
function updateProgressBar() {
|
||||
if (!progressBar) return;
|
||||
const scrollableHeight = document.documentElement.scrollHeight - window.innerHeight;
|
||||
const scrollTop = window.scrollY;
|
||||
|
||||
if (scrollableHeight > 0) {
|
||||
const progress = (scrollTop / scrollableHeight) * 100;
|
||||
progressBar.style.width = `${progress}%`;
|
||||
} else {
|
||||
progressBar.style.width = '0%';
|
||||
}
|
||||
}
|
||||
|
||||
// --- Logika za Scrollspy ---
|
||||
if (headings.length > 0) {
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
entries.forEach(entry => {
|
||||
const id = entry.target.getAttribute('id');
|
||||
const desktopNavLink = desktopNavLinks.find(link => link.getAttribute('href') === `#${id}`);
|
||||
const mobileNavLink = mobileLinksContainer ? mobileLinksContainer.querySelector(`a[href="#${id}"]`) : null;
|
||||
|
||||
if (entry.isIntersecting) {
|
||||
// Posodobi namizno navigacijo
|
||||
if (desktopNavLink) {
|
||||
desktopNavLinks.forEach(link => link.classList.remove('active'));
|
||||
desktopNavLink.classList.add('active');
|
||||
}
|
||||
// Posodobi mobilni naslov in aktivno povezavo v spustnem seznamu
|
||||
if (mobileTitle) {
|
||||
mobileTitle.textContent = entry.target.textContent;
|
||||
}
|
||||
if (mobileNavLink) {
|
||||
mobileLinksContainer.querySelectorAll('a').forEach(link => link.classList.remove('active'));
|
||||
mobileNavLink.classList.add('active');
|
||||
}
|
||||
}
|
||||
});
|
||||
}, {
|
||||
rootMargin: "-100px 0px -50% 0px" // Sproži, ko je naslov v zgornjem delu zaslona
|
||||
});
|
||||
|
||||
headings.forEach(heading => {
|
||||
observer.observe(heading);
|
||||
});
|
||||
}
|
||||
|
||||
// Dodaj poslušalca dogodkov za vrstico napredka
|
||||
window.addEventListener('scroll', updateProgressBar);
|
||||
updateProgressBar(); // Klic ob nalaganju strani
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in Article Scrollspy/Progress Bar setup:', error);
|
||||
}
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* 5. ZAGON FUNKCIJ PO NALOŽITVI STRANI
|
||||
* 6. ZAGON FUNKCIJ PO NALOŽITVI STRANI
|
||||
* ===================================================================
|
||||
*/
|
||||
highlightActiveLink();
|
||||
|
||||
Reference in new issue
Block a user