1( function() { 2 'use strict'; 3 4 // Feature Test 5 if ( 'querySelector' in document && 'addEventListener' in window ) { 6 var goTopBtn = document.querySelector( '.generate-back-to-top' ); 7 8 var trackScroll = function() { 9 var scrolled = window.pageYOffset; 10 var coords = goTopBtn.getAttribute( 'data-start-scroll' ); 11 12 if ( scrolled > coords ) { 13 goTopBtn.classList.add( 'generate-back-to-top__show' ); 14 } 15 16 if ( scrolled < coords ) { 17 goTopBtn.classList.remove( 'generate-back-to-top__show' ); 18 } 19 }; 20 21 // Function to animate the scroll 22 var smoothScroll = function( anchor, duration ) { 23 // Calculate how far and how fast to scroll 24 var startLocation = window.pageYOffset; 25 var endLocation = document.body.offsetTop; 26 var distance = endLocation - startLocation; 27 var increments = distance / ( duration / 16 ); 28 var stopAnimation; 29 30 // Scroll the page by an increment, and check if it's time to stop 31 var animateScroll = function() { 32 window.scrollBy( 0, increments ); 33 stopAnimation(); 34 }; 35 36 // Stop animation when you reach the anchor OR the top of the page 37 stopAnimation = function() { 38 var travelled = window.pageYOffset; 39 if ( travelled <= ( endLocation || 0 ) ) { 40 clearInterval( runAnimation ); 41 document.activeElement.blur(); 42 } 43 }; 44 45 // Loop the animation function 46 var runAnimation = setInterval( animateScroll, 16 ); 47 }; 48 49 if ( goTopBtn ) { 50 // Show the button when scrolling down. 51 window.addEventListener( 'scroll', trackScroll ); 52 53 // Scroll back to top when clicked. 54 goTopBtn.addEventListener( 'click', function( e ) { 55 e.preventDefault(); 56 57 if ( generatepressBackToTop.smooth ) { 58 smoothScroll( document.body, goTopBtn.getAttribute( 'data-scroll-speed' ) || 400 ); 59 } else { 60 window.scrollTo( 0, 0 ); 61 } 62 }, false ); 63 } 64 } 65}() );
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.