Spaces:
Running
Running
| // ESD Study Guide — Shared JS | |
| function toggle(el){el.parentElement.classList.toggle('open')} | |
| function toggleA(el){el.parentElement.classList.toggle('open')} | |
| // Nav active highlighting on scroll | |
| document.addEventListener('DOMContentLoaded',()=>{ | |
| const sections=document.querySelectorAll('section[id]'); | |
| const links=document.querySelectorAll('nav a[href^="#"]'); | |
| const onScroll=()=>{ | |
| let cur=''; | |
| sections.forEach(s=>{if(window.scrollY>=s.offsetTop-90)cur=s.id}); | |
| links.forEach(a=>{a.classList.remove('active');if(a.getAttribute('href')==='#'+cur)a.classList.add('active')}); | |
| }; | |
| window.addEventListener('scroll',onScroll,{passive:true}); | |
| // expand all button | |
| document.querySelectorAll('.expand-all').forEach(btn=>{ | |
| btn.addEventListener('click',()=>{ | |
| const container=btn.closest('section')||document; | |
| container.querySelectorAll('.qa,.asgn-q').forEach(el=>el.classList.add('open')); | |
| btn.textContent='✓ All expanded'; | |
| }); | |
| }); | |
| }); | |