1(function (Drupal, once) { 2 Drupal.behaviors.back_to_top = { 3 attach: function (context, settings) { 4 5 const topButton = document.querySelector('[data-to-top-button]'); 6 7 if (!topButton) { 8 return; 9 } 10 topButton.parentNode.classList.add('hidden'); 11 12 let lastScrollY = 0; 13 14 /** 15 * Only show the button, if scrolled down and then scrolled up a bit 16 */ 17 const updateVisibility = () => { 18 let scrollY = Math.max( 19 window.scrollY, 20 document.documentElement.scrollTop, 21 0 22 ); 23 24 /** 25 * scroll-snap content has its own scroll container, which has to be 26 * queried differentl from the window object 27 */ 28 const scrollSnap = document.getElementById('scrollytelling-snapping--signifier'); 29 if (scrollSnap) { 30 scrollY = scrollSnap.scrollTop; 31 } 32 33 const isVisible = scrollY >= window.innerHeight && scrollY < lastScrollY; // more than viewport height and scrolling up at the moment 34 lastScrollY = scrollY; 35 36 // make sure the scroll-eventlistener doesn't slow down the site 37 window.requestAnimationFrame(() => { 38 if (isVisible) { 39 topButton.parentNode.classList.remove('hidden'); 40 } else { 41 topButton.parentNode.classList.add('hidden'); 42 } 43 }); 44 45 }; 46 47 /** 48 * We can use the window object in general, unless we're using scroll-snapping. 49 * In this case we have to specifically listen on the scroll-snapp container. 50 */ 51 const scrollContent = document.getElementById('scrollytelling-snapping--signifier') || window; 52 scrollContent.addEventListener('scroll', updateVisibility); 53 }, 54 }; 55 56})(Drupal, once);
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.