File size: 1,500 Bytes
3145903
 
2abc9f5
 
 
 
 
 
3145903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Generate navigation items
const sections = [
    { id: 'endpoints', title: 'API Endpoints' },
    { id: 'login', title: '1. Login' },
    { id: 'refresh', title: '2. Refresh Token' },
    { id: 'search', title: '3. Search' },
    { id: 'save', title: '4. Save Data' },
    { id: 'logout', title: '5. Logout' },
    { id: 'workflow', title: 'Workflow Example' }
];

const navItems = document.querySelector('.nav-items');
sections.forEach(section => {
    const item = document.createElement('div');
    item.className = 'nav-item';
    item.textContent = section.title;
    item.setAttribute('data-section', section.id);
    item.addEventListener('click', () => {
        document.getElementById(section.id).scrollIntoView({ behavior: 'smooth' });
    });
    navItems.appendChild(item);
});

// Highlight current section in navigation
const observerCallback = (entries) => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            const currentNav = document.querySelector(`.nav-item[data-section="${entry.target.id}"]`);
            if (currentNav) {
                document.querySelectorAll('.nav-item').forEach(item => {
                    item.style.backgroundColor = '';
                });
                currentNav.style.backgroundColor = '#f3f4f6';
            }
        }
    });
};

const observer = new IntersectionObserver(observerCallback, {
    threshold: 0.2
});

document.querySelectorAll('section').forEach(section => {
    observer.observe(section);
});