1/* global Drupal */ 2 3(function () { 4 5 'use strict'; 6 7 var aboveBreakpoint = false; 8 var breakpoint = 768; 9 var debounceTimer; 10 var className = 'scroll-to-top'; 11 var scrolledState = '--scrolled'; 12 var activeState = '--active'; 13 var duration = 200; 14 15 var magicNumber = 300; // What is this? Was here since the beginning. 16 17 function getViewport() { 18 var e = window; 19 var a = 'inner'; 20 21 if (!('innerWidth' in window)) { 22 a = 'client'; 23 e = document.documentElement || document.body; 24 } 25 return { 26 width: e[a + 'Width'], 27 height: e[a + 'Height'] 28 }; 29 } 30 31 function eachNode(callback, container) { 32 var c = container; 33 if (!c) { 34 c = document; 35 } 36 var nodes = c.querySelectorAll('.' + className); 37 [].forEach.call(nodes, callback); 38 } 39 40 function hide() { 41 eachNode(function (node) { 42 if (!node.classList.contains(className + scrolledState)) { 43 return; 44 } 45 node.classList.remove(className + activeState); 46 setTimeout(function () { 47 node.classList.remove(className + scrolledState); 48 }, duration); 49 }); 50 } 51 52 function show() { 53 eachNode(function (node) { 54 if (node.classList.contains(className + scrolledState)) { 55 return; 56 } 57 node.classList.add(className + scrolledState); 58 setTimeout(function () { 59 node.classList.add(className + activeState); 60 }, duration); 61 }); 62 } 63 64 function handleScroll() { 65 if (!aboveBreakpoint) { 66 hide(); 67 return; 68 } 69 if (document.documentElement.scrollTop <= magicNumber) { 70 hide(); 71 } else { 72 show(); 73 } 74 } 75 76 function setBreakpointState() { 77 clearTimeout(debounceTimer); 78 debounceTimer = setTimeout(function () { 79 aboveBreakpoint = getViewport().width >= breakpoint; 80 handleScroll(); 81 }, 10); 82 } 83 84 function handleClick(e) { 85 window.smoothScroll('#header', 0); 86 e.preventDefault(); 87 } 88 89 function attach(context) { 90 eachNode(function (node) { 91 node.removeAttribute('href'); 92 node.addEventListener('click', handleClick, true); 93 }, context); 94 } 95 96 window.addEventListener('scroll', handleScroll, true); 97 window.addEventListener('resize', setBreakpointState, true); 98 99 setBreakpointState(); 100 101 Drupal.behaviors.scrollToTop = { attach: attach }; 102})(); 103
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.