(a literal px value that does NOT
// change when the primary row collapses). The collapsed bar then
// simply overlays the content like any fixed header rather than
// resizing the document on scroll. Non-toc-bar pages keep using the
// live offsetHeight (their masthead height never changes on scroll).
if (hasTocBar) {
var fullMastheadHeight = parseFloat(
getComputedStyle(document.body).getPropertyValue('--wdg-masthead-height')
);
document.body.style.paddingTop =
(fullMastheadHeight > 0 ? fullMastheadHeight : header.offsetHeight) + 'px';
} else {
document.body.style.paddingTop = header.offsetHeight + 'px';
}
}
updateHeaderState();
// Attach the scroll listener for hero pages (transparent/solid toggle) and
// for any page with the in-masthead submenu bar (so it still collapses to
// the toc-bar on scroll even though it stays solid).
if (isHero || hasTocBar) {
window.addEventListener('scroll', updateHeaderState, { passive: true });
// Safety re-sync: a fast/programmatic jump to the top (browser scroll
// restoration on back-nav, a "scroll to top" action, anchor jumps,
// etc.) can land with coalesced scroll events so the final handler
// run reflects a stale position, leaving the logo/transparency out of
// sync with the resting scrollY. `scrollend` fires once the scroll has
// settled, guaranteeing one final correct update. Harmlessly ignored
// by browsers that don't support it.
window.addEventListener('scrollend', updateHeaderState, { passive: true });
}
window.addEventListener('resize', updateHeaderState);
// Marquee + in-masthead TOC: sticky-toc.js dispatches this when the
// active TOC item changes so we can flip into / out of the forced
// is-solid state immediately on click rather than waiting for the
// next scroll/resize.
window.addEventListener('wdg:toc-section-change', updateHeaderState);
var searchOpenClass = 'is-search-open';
var searchModal = document.getElementById('search-modal');
function openSearchModal() {
if (typeof window._searchModalOpen === 'function') {
window._searchModalOpen();
}
document.querySelectorAll('.js-search-toggle').forEach(function(btn) {
btn.classList.add(searchOpenClass);
btn.setAttribute('aria-expanded', 'true');
});
}
function closeSearchModal() {
if (typeof window._searchModalClose === 'function') {
window._searchModalClose();
}
document.querySelectorAll('.js-search-toggle').forEach(function(btn) {
btn.classList.remove(searchOpenClass);
btn.setAttribute('aria-expanded', 'false');
});
}
document.querySelectorAll('.js-search-toggle').forEach(function(btn) {
btn.addEventListener('click', function(e) {
e.preventDefault();
if (searchModal && searchModal.classList.contains('is-open')) {
closeSearchModal();
} else {
openSearchModal();
}
});
});
var mobileSearchBtn = document.querySelector('.js-mobile-search-open');
if (mobileSearchBtn) {
mobileSearchBtn.addEventListener('click', function(e) {
e.preventDefault();
var mobileOverlay = document.getElementById('mobile-menu');
if (mobileOverlay) {
mobileOverlay.setAttribute('aria-hidden', 'true');
mobileOverlay.classList.remove('is-open');
}
openSearchModal();
});
}
function updateAdminBarState() {
var ab = document.getElementById('wpadminbar');
if (!ab) return;
var rect = ab.getBoundingClientRect();
var hidden = rect.bottom <= 0;
document.body.classList.toggle('adminbar-hidden', hidden);
}
updateAdminBarState();
window.addEventListener('scroll', updateAdminBarState, { passive: true });
window.addEventListener('resize', updateAdminBarState);
})();