1/** 2 * sleepyDragon template scripts 3 * ----------------------------- 4 * Back to Top (accessible) 5 */ 6(function () { 7 'use strict'; 8 9 const backToTop = document.querySelector('.back-to-top'); 10 if (!backToTop) return; 11 12 const OFFSET_PX = 220; 13 14 const prefersReducedMotion = 15 window.matchMedia && 16 window.matchMedia('(prefers-reduced-motion: reduce)').matches; 17 18 if (!backToTop.hasAttribute('aria-label') && !backToTop.getAttribute('aria-labelledby')) { 19 backToTop.setAttribute('aria-label', 'Back to top'); 20 } 21 22 const updateBackToTopVisibility = () => { 23 if (window.scrollY > OFFSET_PX) { 24 backToTop.style.display = ''; 25 backToTop.classList.add('is-visible'); 26 } else { 27 backToTop.classList.remove('is-visible'); 28 backToTop.style.display = 'none'; 29 } 30 }; 31 32 // Initial state + scroll updates 33 updateBackToTopVisibility(); 34 window.addEventListener('scroll', updateBackToTopVisibility, { passive: true }); 35 36 backToTop.addEventListener('click', (event) => { 37 event.preventDefault(); 38 39 const target = 40 document.getElementById('top'); 41 42 const focusTarget = () => { 43 if (!target) return; 44 45 if (!target.hasAttribute('tabindex')) { 46 target.setAttribute('tabindex', '-1'); 47 } 48 49 try { 50 target.focus({ preventScroll: true }); 51 } catch (e) { 52 target.focus(); 53 } 54 }; 55 56 if (prefersReducedMotion) { 57 window.scrollTo(0, 0); 58 focusTarget(); 59 return; 60 } 61 62 window.scrollTo({ top: 0, behavior: 'smooth' }); 63 64 const waitForTop = () => { 65 if (window.scrollY <= 1) { 66 focusTarget(); 67 return; 68 } 69 requestAnimationFrame(waitForTop); 70 }; 71 72 requestAnimationFrame(waitForTop); 73 }); 74})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.