1/** 2 * @file 3 * Back To Top behaviors. 4 */ 5(function ($, Drupal, once, drupalSettings) { 6 7 var frame; 8 var scrollTo = function (to, duration) { 9 var element = document.scrollingElement || document.documentElement, 10 start = element.scrollTop, 11 change = to - start, 12 startTs = performance.now(), 13 easeOutQuart = function (t, b, c, d) { 14 t /= d; 15 t--; 16 return -c * (t * t * t * t - 1) + b; 17 }, 18 animateScroll = function (ts) { 19 var currentTime = ts - startTs; 20 element.scrollTop = parseInt(easeOutQuart(currentTime, start, change, duration)); 21 if (currentTime < duration) { 22 frame = requestAnimationFrame(animateScroll); 23 } else { 24 element.scrollTop = to; 25 } 26 }; 27 requestAnimationFrame(animateScroll); 28 }; 29 30 Drupal.behaviors.backtotop = { 31 attach: function (context, settings) { 32 let isMobile = window.matchMedia("only screen and (max-width: 760px)").matches; 33 if (!(settings.back_to_top.back_to_top_prevent_on_mobile && isMobile)) { 34 var exist = $('#backtotop').length; 35 if (exist == 0) { 36 $(once('backtotop', 'body'), context).each(function () { 37 $('body').append("<nav aria-label='" + Drupal.t("Back to top") + "'><button id='backtotop' aria-label='" + Drupal.t("Back to top") + "'>" + settings.back_to_top.back_to_top_button_text + "</button></nav>"); 38 }); 39 } 40 } 41 42 backToTop(); 43 $(document).on("scroll", function() { 44 backToTop(); 45 }); 46 47 $(once('backtotop', '#backtotop'), context).each(function () { 48 $(this).click(function () { 49 $("html, body").bind("scroll mousedown DOMMouseScroll mousewheel keyup", function () { 50 if (typeof frame !== 'undefined') { 51 window.cancelAnimationFrame(frame); 52 } 53 }); 54 speed = settings.back_to_top.back_to_top_speed; 55 if (speed == null) { 56 speed = 1200; 57 } 58 scrollTo(0, speed); 59 }); 60 }); 61 62 /** 63 * Hide show back to top links. 64 */ 65 function backToTop() { 66 if ($(window).scrollTop() > settings.back_to_top.back_to_top_button_trigger) { 67 $('#backtotop').fadeIn(); 68 } else { 69 $('#backtotop').fadeOut(); 70 } 71 } 72 } 73 }; 74})(jQuery, Drupal, once, drupalSettings);
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.