| 1 | (function () { |
| 2 | const versionSelect = document.querySelector('[data-release-version]'); |
| 3 | versionSelect?.addEventListener('change', () => { |
| 4 | const version = String(versionSelect.value || '').replace(/^v/, ''); |
| 5 | if (/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) { |
| 6 | window.location.href = `/changelog/v${version}/`; |
| 7 | } |
| 8 | }); |
| 9 | |
| 10 | const links = Array.from(document.querySelectorAll('.release-toc a[href^="#"]')); |
| 11 | const sections = links.map((link) => document.querySelector(link.getAttribute('href'))).filter(Boolean); |
| 12 | if (!links.length || !sections.length) return; |
| 13 | |
| 14 | let ticking = false; |
| 15 | const update = () => { |
| 16 | ticking = false; |
| 17 | let current = sections[0]; |
| 18 | for (const section of sections) { |
| 19 | if (section.getBoundingClientRect().top <= 150) current = section; |
| 20 | } |
| 21 | links.forEach((link) => link.classList.toggle('active', link.hash === `#${current.id}`)); |
| 22 | }; |
| 23 | const queue = () => { |
| 24 | if (ticking) return; |
| 25 | ticking = true; |
| 26 | requestAnimationFrame(update); |
| 27 | }; |
| 28 | window.addEventListener('scroll', queue, { passive: true }); |
| 29 | window.addEventListener('resize', queue, { passive: true }); |
| 30 | update(); |
| 31 | })(); |
| 32 |