File size: 985 Bytes
0dcd1bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// 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';
    });
  });
});