|
| 1 | + |
| 2 | +const $ = (s, scope=document) => scope.querySelector(s); |
| 3 | +const $$ = (s, scope=document) => [...scope.querySelectorAll(s)]; |
| 4 | + |
| 5 | +const navToggle = $('.nav-toggle'); |
| 6 | +const navLinks = $('.nav-links'); |
| 7 | +navToggle?.addEventListener('click', () => { |
| 8 | + const open = navLinks.classList.toggle('open'); |
| 9 | + navToggle.setAttribute('aria-expanded', String(open)); |
| 10 | +}); |
| 11 | +$$('.nav-links a').forEach(a => a.addEventListener('click', () => navLinks?.classList.remove('open'))); |
| 12 | + |
| 13 | +const observer = new IntersectionObserver(entries => entries.forEach(e => { |
| 14 | + if(e.isIntersecting){ e.target.classList.add('visible'); observer.unobserve(e.target); } |
| 15 | +}), {threshold:.08}); |
| 16 | +$$('.fade').forEach(el => observer.observe(el)); |
| 17 | + |
| 18 | +$$('[data-copy]').forEach(button => button.addEventListener('click', async () => { |
| 19 | + const target = document.getElementById(button.dataset.copy); |
| 20 | + try { await navigator.clipboard.writeText(target.innerText); button.textContent='Copied'; } |
| 21 | + catch { button.textContent='Select & copy'; } |
| 22 | + setTimeout(() => button.textContent='Copy', 1500); |
| 23 | +})); |
| 24 | + |
| 25 | +const modal = $('#image-modal'); |
| 26 | +const modalImg = $('#modal-image'); |
| 27 | +$$('[data-full]').forEach(card => card.addEventListener('click', () => { |
| 28 | + if(!modal || !modalImg) return; |
| 29 | + modalImg.src = card.dataset.full; |
| 30 | + modalImg.alt = card.querySelector('img')?.alt || 'Expanded engineering evidence'; |
| 31 | + modal.showModal(); |
| 32 | +})); |
| 33 | +$('.modal-close')?.addEventListener('click', () => modal.close()); |
| 34 | +modal?.addEventListener('click', e => { if(e.target === modal) modal.close(); }); |
| 35 | + |
| 36 | +// Derive the repository URL automatically when hosted on GitHub Pages. |
| 37 | +const host = location.hostname; |
| 38 | +let repoUrl = 'https://github.com/YOUR-USERNAME/opensat-mission-lab'; |
| 39 | +if(host.endsWith('.github.io')) { |
| 40 | + const owner = host.split('.')[0]; |
| 41 | + const repo = location.pathname.split('/').filter(Boolean)[0]; |
| 42 | + repoUrl = repo ? `https://github.com/${owner}/${repo}` : `https://github.com/${owner}/${owner}.github.io`; |
| 43 | +} |
| 44 | +$$('[data-repo-link]').forEach(a => a.href = repoUrl); |
| 45 | +$$('[data-repo-text]').forEach(el => el.textContent = repoUrl.replace('https://github.com/','')); |
| 46 | + |
| 47 | +const year = $('#year'); if(year) year.textContent = new Date().getFullYear(); |
0 commit comments