60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
let dotNetObject;
|
|
let observer;
|
|
let sections;
|
|
|
|
export function initialize(dotNetHelper) {
|
|
dotNetObject = dotNetHelper;
|
|
|
|
// Setup IntersectionObserver for navigation highlighting
|
|
setupIntersectionObserver();
|
|
|
|
// Setup click handlers for navigation
|
|
setupNavigationClickObserver();
|
|
}
|
|
|
|
function setupIntersectionObserver() {
|
|
const observer = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
const sectionId = entry.target.id;
|
|
dotNetObject.invokeMethodAsync('HandleSectionChange', sectionId);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.5
|
|
});
|
|
|
|
sections = document.querySelectorAll('.scroll_section');
|
|
sections.forEach(section => {
|
|
observer.observe(section);
|
|
});
|
|
}
|
|
|
|
function setupNavigationClickObserver() {
|
|
const navLinks = document.querySelectorAll('.nav_option');
|
|
navLinks.forEach(link => {
|
|
link.addEventListener('click', (event) => {
|
|
event.preventDefault();
|
|
const targetId = link.getAttribute('href');
|
|
scrollToSection(targetId.substring(1));
|
|
});
|
|
});
|
|
}
|
|
|
|
export function scrollToSection(sectionId) {
|
|
const targetSection = document.getElementById(sectionId);
|
|
if (targetSection) {
|
|
targetSection.scrollIntoView({
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
}
|
|
|
|
export function dispose() {
|
|
if (observer) {
|
|
sections.forEach(section => {
|
|
observer.unobserve(section);
|
|
});
|
|
}
|
|
}
|