| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
document.querySelectorAll('.bkbg-sth-header[data-sticky]').forEach(function (header) { |
| 5 |
var isSticky = header.dataset.sticky === '1'; |
| 6 |
var shouldShrink = header.dataset.shrink === '1'; |
| 7 |
|
| 8 |
if (!isSticky) return; |
| 9 |
|
| 10 |
var lastScrollY = 0; |
| 11 |
|
| 12 |
function handleScroll() { |
| 13 |
var scrollY = window.scrollY || window.pageYOffset; |
| 14 |
var isScrolled = scrollY > 10; |
| 15 |
|
| 16 |
if (isScrolled) { |
| 17 |
header.classList.add('bkbg-sth-is-scrolled'); |
| 18 |
} else { |
| 19 |
header.classList.remove('bkbg-sth-is-scrolled'); |
| 20 |
} |
| 21 |
|
| 22 |
if (shouldShrink && isScrolled) { |
| 23 |
header.classList.add('bkbg-sth-shrunk'); |
| 24 |
} else { |
| 25 |
header.classList.remove('bkbg-sth-shrunk'); |
| 26 |
} |
| 27 |
|
| 28 |
lastScrollY = scrollY; |
| 29 |
} |
| 30 |
|
| 31 |
window.addEventListener('scroll', handleScroll, { passive: true }); |
| 32 |
handleScroll(); // init state |
| 33 |
|
| 34 |
/* ---- Mobile menu toggle ---- */ |
| 35 |
var hamburger = header.querySelector('.bkbg-sth-hamburger'); |
| 36 |
var mobileNav = header.querySelector('.bkbg-sth-mobile-nav'); |
| 37 |
|
| 38 |
if (hamburger && mobileNav) { |
| 39 |
hamburger.addEventListener('click', function () { |
| 40 |
var expanded = hamburger.getAttribute('aria-expanded') === 'true'; |
| 41 |
hamburger.setAttribute('aria-expanded', String(!expanded)); |
| 42 |
mobileNav.setAttribute('aria-hidden', String(expanded)); |
| 43 |
|
| 44 |
if (!expanded) { |
| 45 |
mobileNav.removeAttribute('style'); |
| 46 |
} else { |
| 47 |
mobileNav.style.display = 'none'; |
| 48 |
} |
| 49 |
}); |
| 50 |
} |
| 51 |
}); |
| 52 |
})(); |
| 53 |
|