// ============================ // 1. 모바일 드롭다운 토글 // ============================ document.querySelectorAll('.select > button').forEach(btn=>{ btn.addEventListener('click', function(e){ e.stopPropagation(); const parent = this.parentElement; parent.classList.toggle('active'); document.querySelectorAll('.select').forEach(el=>{ if(el !== parent) el.classList.remove('active'); }); }); }); // ============================ // 2. 모바일 메뉴 클릭 → 이동 // ============================ document.querySelectorAll('.depth1Select li').forEach(li=>{ li.addEventListener('click', function(){ const url = this.dataset.url; window.location.href = url; }); }); // ============================ // 3. 현재 페이지 active 처리 (핵심 유지) // ============================ window.addEventListener('DOMContentLoaded', function(){ const currentUrl = window.location.pathname; // PC active document.querySelectorAll('.depth1 > li').forEach(li=>{ const a = li.querySelector('a'); if(currentUrl.includes(a.getAttribute('href'))){ li.classList.add('active'); // 모바일 텍스트 변경 document.querySelector('.depth1Select button').innerHTML = a.innerText + ' '; } }); }); // ============================ // 4. 외부 클릭 닫기 // ============================ document.addEventListener('click', function(e){ if(!e.target.closest('.select')){ document.querySelectorAll('.select').forEach(el=>{ el.classList.remove('active'); }); } });