1/** 2 * ---------------------------------------- 3 * Back to Top Button 4 */ 5export default function backToTop() { 6 const backButton = document.querySelector(".btn-back-to-top"); 7 // if (!backButton) return; // Ensure the button exists before proceeding 8 9 // const scrollContainer = document.documentElement || document.body; 10 11 // const handleScroll = () => { 12 // // console.log("Current Scroll Position:", scrollContainer.scrollTop); 13 // if (scrollContainer.scrollTop >= 100) { 14 // backButton.classList.add("show"); 15 // backButton.classList.remove("hide"); 16 // } else { 17 // backButton.classList.remove("show"); 18 // backButton.classList.add("hide"); 19 // } 20 // }; 21 22 // const handleClick = () => { 23 // // console.log("Clicked the button, starting scroll animation..."); 24 // let startTimestamp = null; 25 // const duration = 1000; // Duration in milliseconds 26 // const totalScroll = scrollContainer.scrollHeight - window.innerHeight; 27 28 // const animateScroll = (timestamp) => { 29 // if (!startTimestamp) startTimestamp = timestamp; 30 // const progress = Math.min((timestamp - startTimestamp) * duration, 1); 31 // const easeInOutQuad = (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t); 32 // window.scrollTo({ 33 // top: 0, 34 // behavior: "smooth", 35 // }); 36 // // console.log("Scroll Progress:", progress); 37 // if (progress < 1) requestAnimationFrame(animateScroll); 38 // }; 39 40 // const easeInOut = (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t); 41 // const reverseEaseInOut = (t) => 1 - easeInOutQuad(1 - t); 42 // requestAnimationFrame(animateScroll); 43 // }; 44 45 // document.addEventListener("scroll", handleScroll); 46 // backButton.addEventListener("click", handleClick); 47 48 function Util() {} 49 /* 50 class manipulation functions 51*/ 52 Util.hasClass = (el, className) => { 53 if (el.classList) return el.classList.contains(className); 54 else 55 return !!el.className.match( 56 new RegExp("(\\s|^)" + className + "(\\s|$)"), 57 ); 58 }; 59 60 Util.scrollTo = (final, duration, cb) => { 61 var start = window.scrollY || document.documentElement.scrollTop, 62 currentTime = null; 63 64 var animateScroll = (timestamp) => { 65 if (!currentTime) currentTime = timestamp; 66 var progress = timestamp - currentTime; 67 if (progress > duration) progress = duration; 68 var val = Math.easeInOutQuad(progress, start, final - start, duration); 69 window.scrollTo(0, val); 70 if (progress < duration) { 71 window.requestAnimationFrame(animateScroll); 72 } else { 73 cb && cb(); 74 } 75 }; 76 77 window.requestAnimationFrame(animateScroll); 78 }; 79 80 Util.addClass = (el, className) => { 81 var classList = className.split(" "); 82 if (el.classList) el.classList.add(classList[0]); 83 else if (!Util.hasClass(el, classList[0])) 84 el.className += " " + classList[0]; 85 if (classList.length > 1) Util.addClass(el, classList.slice(1).join(" ")); 86 }; 87 88 Util.removeClass = (el, className) => { 89 var classList = className.split(" "); 90 if (el.classList) el.classList.remove(classList[0]); 91 else if (Util.hasClass(el, classList[0])) { 92 var reg = new RegExp("(\\s|^)" + classList[0] + "(\\s|$)"); 93 el.className = el.className.replace(reg, " "); 94 } 95 if (classList.length > 1) 96 Util.removeClass(el, classList.slice(1).join(" ")); 97 }; 98 99 Util.toggleClass = (el, className, bool) => { 100 if (bool) Util.addClass(el, className); 101 else Util.removeClass(el, className); 102 }; 103 104 Util.setAttributes = (el, attrs) => { 105 for (var key in attrs) { 106 el.setAttribute(key, attrs[key]); 107 } 108 }; 109 110 Math.easeInOutQuad = (t, b, c, d) => { 111 t /= d / 2; 112 if (t < 1) return (c / 2) * t * t + b; 113 t--; 114 return (-c / 2) * (t * (t - 2) - 1) + b; 115 }; 116 117 // Back to Top - by CodyHouse.co 118 // var backTop = document.getElementsByClassName(".btn-back-to-top")[0], 119 let backTop = document.querySelector(".btn-back-to-top"), 120 offset = 100, // browser window scroll (in pixels) after which the "back to top" link is shown 121 offsetOpacity = 99999, //browser window scroll (in pixels) after which the "back to top" link opacity is reduced 122 scrollDuration = 700, 123 scrolling = false;
124 125 if (backTop) { 126 //update back to top visibility on scrolling 127 window.addEventListener("scroll", (event) => { 128 if (!scrolling) { 129 scrolling = true; 130 !window.requestAnimationFrame 131 ? setTimeout(handleScroll, 250) 132 : window.requestAnimationFrame(handleScroll); 133 } 134 }); 135 136 //smooth scroll to top 137 backTop.addEventListener("click", (event) => { 138 event.preventDefault(); 139 !window.requestAnimationFrame 140 ? window.scrollTo(0, 0) 141 : Util.scrollTo(0, scrollDuration); 142 }); 143 } 144 145 function checkBackToTop() { 146 var windowTop = window.scrollY || document.documentElement.scrollTop; 147 windowTop > offset 148 ? Util.addClass(backTop, "show") 149 : Util.removeClass(backTop, "show cd-top--fade-out"); 150 windowTop > offsetOpacity && Util.addClass(backTop, "cd-top--fade-out"); 151 scrolling = false; 152 } 153 154 const handleScroll = () => { 155 var windowTop = window.scrollY || document.documentElement.scrollTop; 156 windowTop >= offset 157 ? Util.addClass(backTop, "show") 158 : Util.removeClass(backTop, "show hide"); 159 windowTop > offsetOpacity && Util.addClass(backTop, "hide"); 160 scrolling = false; 161 162 // const handleScroll = () => { 163 // // // console.log("Current Scroll Position:", scrollContainer.scrollTop); 164 // if (scrollContainer.scrollTop >= offset) { 165 // backButton.classList.add("show"); 166 // backButton.classList.remove("hide"); 167 // } else { 168 // backButton.classList.remove("show"); 169 // backButton.classList.add("hide"); 170 // } 171 // }; 172 }; 173}
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.