1 2(function ($, Drupal, window, document, undefined) { 3 Drupal.behaviors.navbarScroll = { 4 attach: function(context, settings) { 5 var scrollInitialPosition = 39; // initial scroll position to start changing classes // scss $top-bar--height 6 var lastScrollTop = 0; // var declaration to scroll functionaility 7 8 $(window).scroll(function() { 9 if($("#navbar").hasClass("navbar-fixed-top")){ 10 // Check if the scroll is on top of the page, to remove the background 11 // of the menu when it has a banner top 12 if($(window).scrollTop() === 0) { 13 $("#navbar").removeClass("navbar-is-scrolled"); 14 }else{ 15 $("#navbar").addClass("navbar-is-scrolled"); 16 } 17 18 // $('body').removeClass('stop-scrolling'); 19 // check if the megamenu is open (so this doesn't make the navbar hide when scrolled) 20 if($(".tb-megamenu-item.level-1").hasClass("open")){ 21 // If has one open megamenu, always show the navbar (as if the page was scrolled towards top) 22 $("#navbar").addClass("navbar-is-scrolled--top"); 23 // Disable the scroll on body 24 disableScroll(); 25 // Enable when the mouse goes out of navbar 26 $("#navbar").mouseout(function(){ 27 enableScroll(); 28 }); 29 }else{ 30 // Check the direction of the scroll so we ca show the menu 31 // if the user is scrolling top 32 var actualScrollTop = $(this).scrollTop(); 33 if (actualScrollTop > lastScrollTop){ 34 // downscroll code 35 $("#navbar").removeClass("navbar-is-scrolled--top"); 36 if($('.contact-card').length && $('.contact-card').hasClass("open")){ 37 $('.contact-card').removeClass('open'); 38 $(".view-banner-page-top .carousel-inner .item .title").animate({width: "100%"}, 0); 39 $(".region-navigation").animate({marginRight: "0"}); 40 } 41 } else { 42 // upscroll code 43 $("#navbar").addClass("navbar-is-scrolled--top"); 44 } 45 lastScrollTop = (actualScrollTop > scrollInitialPosition)? actualScrollTop : scrollInitialPosition; 46 } 47 } 48 }); 49 50 51 ///* Function to disable scrolling 52 //* thanks to https://stackoverflow.com/a/4770179/2270775 53 // left: 37, up: 38, right: 39, down: 40, 54 // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36 55 var keys = {37: 1, 38: 1, 39: 1, 40: 1}; 56 57 function preventDefault(e) { 58 e = e || window.event; 59 if (e.preventDefault) 60 e.preventDefault(); 61 e.returnValue = false; 62 } 63 64 function preventDefaultForScrollKeys(e) { 65 if (keys[e.keyCode]) { 66 preventDefault(e); 67 return false; 68 } 69 } 70 71 function disableScroll() { 72 if (window.addEventListener) // older FF 73 window.addEventListener('DOMMouseScroll', preventDefault, false); 74 window.onwheel = preventDefault; // modern standard 75 window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE 76 window.ontouchmove = preventDefault; // mobile 77 document.onkeydown = preventDefaultForScrollKeys; 78 } 79 80 function enableScroll() { 81 if (window.removeEventListener) 82 window.removeEventListener('DOMMouseScroll', preventDefault, false); 83 window.onmousewheel = document.onmousewheel = null; 84 window.onwheel = null; 85 window.ontouchmove = null; 86 document.onkeydown = null; 87 } 88 ///* /Function to disable scrolling 89 90 } 91 }; 92 93 94})(jQuery, Drupal, this, this.document);
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.