Spaces:
Running
Running
File size: 4,840 Bytes
dfbfae0 |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
(function () {
const qs = (sel, ctx = document) => ctx.querySelector(sel);
const qsa = (sel, ctx = document) => Array.from(ctx.querySelectorAll(sel));
// Mobile menu
const menuToggle = qs('#menuToggle');
const mobileMenu = qs('#mobileMenu');
if (menuToggle && mobileMenu) {
menuToggle.addEventListener('click', () => {
const isHidden = mobileMenu.classList.contains('hidden');
mobileMenu.classList.toggle('hidden', !isHidden);
menuToggle.setAttribute('aria-expanded', String(isHidden));
});
}
// Expand/Collapse all curriculum modules
const expandBtn = qs('#expandAll');
const modules = qsa('.module');
if (expandBtn && modules.length) {
const toggleAll = () => {
const shouldOpen = expandBtn.dataset.state !== 'open';
modules.forEach((mod) => {
const content = qs('.module-content', mod);
const icon = qs('.module-icon', mod);
const summaryBtn = qs('.module-toggle', mod);
if (shouldOpen) {
openModule(mod, content, icon, summaryBtn, false);
} else {
closeModule(mod, content, icon, summaryBtn, false);
}
});
expandBtn.dataset.state = shouldOpen ? 'open' : 'closed';
const icon = qs('i', expandBtn);
if (icon) {
icon.setAttribute('data-feather', shouldOpen ? 'minus-square' : 'plus-square');
// Replace icon
if (window.feather && typeof feather.replace === 'function') {
feather.replace();
}
}
};
expandBtn.addEventListener('click', toggleAll);
}
// Individual module toggle
function openModule(module, content, icon, summaryBtn, animate = true) {
summaryBtn.setAttribute('aria-expanded', 'true');
content.classList.remove('hidden');
content.classList.add('open');
if (icon) icon.style.transform = 'rotate(180deg)';
if (animate) {
// auto height animation
content.style.maxHeight = '0px';
requestAnimationFrame(() => {
content.style.maxHeight = content.scrollHeight + 'px';
});
const onEnd = (e) => {
if (e.propertyName !== 'max-height') return;
content.style.maxHeight = 'none';
content.removeEventListener('transitionend', onEnd);
};
content.addEventListener('transitionend', onEnd);
} else {
content.style.maxHeight = 'none';
}
}
function closeModule(module, content, icon, summaryBtn, animate = true) {
summaryBtn.setAttribute('aria-expanded', 'false');
if (animate) {
// from current height to 0
content.style.maxHeight = content.scrollHeight + 'px';
requestAnimationFrame(() => {
content.style.maxHeight = '0px';
});
const onEnd = (e) => {
if (e.propertyName !== 'max-height') return;
content.classList.remove('open');
content.classList.add('hidden');
content.style.maxHeight = '';
content.removeEventListener('transitionend', onEnd);
};
content.addEventListener('transitionend', onEnd);
} else {
content.classList.remove('open');
content.classList.add('hidden');
content.style.maxHeight = '';
}
if (icon) icon.style.transform = 'rotate(0deg)';
}
modules.forEach((mod) => {
const content = qs('.module-content', mod);
const icon = qs('.module-icon', mod);
const summaryBtn = qs('.module-toggle', mod);
summaryBtn.addEventListener('click', (e) => {
e.preventDefault();
const isOpen = summaryBtn.getAttribute('aria-expanded') === 'true';
if (isOpen) {
closeModule(mod, content, icon, summaryBtn, true);
} else {
openModule(mod, content, icon, summaryBtn, true);
}
});
});
// FAQ accordion behavior: only one open at a time
const faqs = qsa('#faq details');
if (faqs.length) {
faqs.forEach((faq) => {
faq.addEventListener('toggle', () => {
if (faq.open) {
faqs.forEach((other) => {
if (other !== faq) other.removeAttribute('open');
});
}
});
});
}
// Smooth scroll offset for fixed header
const offset = 16; // header height-ish
qsa('a[href^="#"]').forEach((a) => {
a.addEventListener('click', (e) => {
const id = a.getAttribute('href');
if (!id || id === '#') return;
const el = qs(id);
if (!el) return;
e.preventDefault();
const top = el.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top, behavior: 'smooth' });
history.pushState(null, '', id);
});
});
// Footer year
const yearEl = qs('#year');
if (yearEl) {
yearEl.textContent = String(new Date().getFullYear());
}
// Replace Feather icons if dynamically inserted
if (window.feather && typeof feather.replace === 'function') {
feather.replace();
}
})(); |