|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
const menu = document.getElementById('quick-access-menu'); |
|
|
if (!menu) return; |
|
|
|
|
|
const menuLinks = menu.getElementsByTagName('a'); |
|
|
const sections = Array.from(document.querySelectorAll('section[id], div[id="bibtex"]')); |
|
|
|
|
|
function isPageBottom() { |
|
|
return (window.innerHeight + window.scrollY) >= document.body.offsetHeight - 50; |
|
|
} |
|
|
|
|
|
function getCurrentSection() { |
|
|
if (isPageBottom()) { |
|
|
return sections[sections.length - 1].id; |
|
|
} |
|
|
|
|
|
const scrollPosition = window.scrollY; |
|
|
|
|
|
for (let i = sections.length - 1; i >= 0; i--) { |
|
|
const section = sections[i]; |
|
|
const sectionTop = section.offsetTop - 100; |
|
|
|
|
|
if (scrollPosition >= sectionTop) { |
|
|
return section.id; |
|
|
} |
|
|
} |
|
|
|
|
|
return sections[0].id; |
|
|
} |
|
|
|
|
|
function highlightMenuLink() { |
|
|
const currentSection = getCurrentSection(); |
|
|
|
|
|
Array.from(menuLinks).forEach(link => { |
|
|
link.classList.remove('active'); |
|
|
if (link.getAttribute('href').slice(1) === currentSection) { |
|
|
link.classList.add('active'); |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
window.addEventListener('scroll', highlightMenuLink); |
|
|
|
|
|
|
|
|
highlightMenuLink(); |
|
|
|
|
|
|
|
|
Array.from(menuLinks).forEach(link => { |
|
|
link.addEventListener('click', function(e) { |
|
|
e.preventDefault(); |
|
|
const targetId = this.getAttribute('href').slice(1); |
|
|
const targetSection = document.getElementById(targetId); |
|
|
|
|
|
if (targetSection) { |
|
|
window.scrollTo({ |
|
|
top: targetSection.offsetTop - 50, |
|
|
behavior: 'smooth' |
|
|
}); |
|
|
} else { |
|
|
console.warn(`Section with id "${targetId}" not found`); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}); |