1// Credit: https://codyhouse.co/gem/back-to-top/ 2// License: https://codyhouse.co/mit 3// Details: https://codyhouse.co/license#experiments 4 5// Utility function 6function Util () {}; 7 8/* 9 class manipulation functions 10*/ 11Util.hasClass = function(el, className) { 12 if (el.classList) return el.classList.contains(className); 13 else return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)')); 14}; 15 16Util.addClass = function(el, className) { 17 var classList = className.split(' '); 18 if (el.classList) el.classList.add(classList[0]); 19 else if (!Util.hasClass(el, classList[0])) el.className += " " + classList[0]; 20 if (classList.length > 1) Util.addClass(el, classList.slice(1).join(' ')); 21}; 22 23Util.removeClass = function(el, className) { 24 var classList = className.split(' '); 25 if (el.classList) el.classList.remove(classList[0]); 26 else if(Util.hasClass(el, classList[0])) { 27 var reg = new RegExp('(\\s|^)' + classList[0] + '(\\s|$)'); 28 el.className=el.className.replace(reg, ' '); 29 } 30 if (classList.length > 1) Util.removeClass(el, classList.slice(1).join(' ')); 31}; 32 33/* 34 Smooth Scroll 35*/ 36 37Util.scrollTo = function(final, duration, cb, scrollEl) { 38 var element = scrollEl || window; 39 var start = element.scrollTop || document.documentElement.scrollTop, 40 currentTime = null; 41 42 if(!scrollEl) start = window.scrollY || document.documentElement.scrollTop; 43 44 var animateScroll = function(timestamp){ 45 if (!currentTime) currentTime = timestamp; 46 var progress = timestamp - currentTime; 47 if(progress > duration) progress = duration; 48 var val = Math.easeInOutQuad(progress, start, final-start, duration); 49 element.scrollTo(0, val); 50 if(progress < duration) { 51 window.requestAnimationFrame(animateScroll); 52 } else { 53 cb && cb(); 54 } 55 }; 56 57 window.requestAnimationFrame(animateScroll); 58}; 59 60/* 61 Animation curves 62*/ 63Math.easeInOutQuad = function (t, b, c, d) { 64 t /= d/2; 65 if (t < 1) return c/2*t*t + b; 66 t--; 67 return -c/2 * (t*(t-2) - 1) + b; 68}; 69 70(function(){ 71 jQuery(document).ready(() => { 72 // Back to Top - by CodyHouse.co 73 var backTop = document.getElementsByClassName('js-cd-top')[0], 74 offset = 300, // browser window scroll (in pixels) after which the "back to top" link is shown 75 offsetOpacity = 1200, //browser window scroll (in pixels) after which the "back to top" link opacity is reduced 76 scrollDuration = 700, 77 scrolling = false; 78 if( backTop ) { 79 //update back to top visibility on scrolling 80 window.addEventListener("scroll", function(event) { 81 if( !scrolling ) { 82 scrolling = true; 83 (!window.requestAnimationFrame) ? setTimeout(checkBackToTop, 250) : window.requestAnimationFrame(checkBackToTop); 84 } 85 }); 86 87 //smooth scroll to top 88 backTop.addEventListener('click', function(event) { 89 event.preventDefault(); 90 (!window.requestAnimationFrame) ? window.scrollTo(0, 0) : Util.scrollTo(0, scrollDuration); 91 }); 92 } 93 94 function checkBackToTop() { 95 var windowTop = window.scrollY || document.documentElement.scrollTop; 96 ( windowTop > offset ) ? Util.addClass(backTop, 'cd-top--is-visible') : Util.removeClass(backTop, 'cd-top--is-visible cd-top--fade-out'); 97 ( windowTop > offsetOpacity ) && Util.addClass(backTop, 'cd-top--fade-out'); 98 scrolling = false; 99 } 100 }); 101 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.