Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
/* eslint-disable no-inner-declarations */
|
2020-10-21 10:41:33 +00:00
|
|
|
((Drupal) => {
|
Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
/**
|
|
|
|
* Olivero helper functions.
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
Drupal.olivero = {};
|
|
|
|
|
|
|
|
function isDesktopNav() {
|
|
|
|
const navButtons = document.querySelector('.mobile-buttons');
|
|
|
|
return (
|
|
|
|
window.getComputedStyle(navButtons).getPropertyValue('display') === 'none'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Drupal.olivero.isDesktopNav = isDesktopNav;
|
|
|
|
|
|
|
|
const wideNavButton = document.querySelector('.nav-primary__button');
|
|
|
|
const siteHeaderFixable = document.querySelector('.site-header__fixable');
|
|
|
|
|
|
|
|
function wideNavIsOpen() {
|
|
|
|
return wideNavButton.getAttribute('aria-expanded') === 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
function showWideNav() {
|
|
|
|
if (isDesktopNav()) {
|
|
|
|
wideNavButton.setAttribute('aria-expanded', 'true');
|
|
|
|
siteHeaderFixable.classList.add('is-expanded');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the wide nav button to be closed (its default state).
|
|
|
|
function hideWideNav() {
|
|
|
|
if (isDesktopNav()) {
|
|
|
|
wideNavButton.setAttribute('aria-expanded', 'false');
|
|
|
|
siteHeaderFixable.classList.remove('is-expanded');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only enable scroll effects if the browser supports Intersection Observer.
|
|
|
|
// @see https://github.com/w3c/IntersectionObserver/blob/master/polyfill/intersection-observer.js#L19-L21
|
|
|
|
if (
|
|
|
|
'IntersectionObserver' in window &&
|
|
|
|
'IntersectionObserverEntry' in window &&
|
|
|
|
'intersectionRatio' in window.IntersectionObserverEntry.prototype
|
|
|
|
) {
|
|
|
|
const fixableElements = document.querySelectorAll('.fixable');
|
|
|
|
|
|
|
|
function toggleDesktopNavVisibility(entries) {
|
|
|
|
if (!isDesktopNav()) return;
|
|
|
|
|
2020-10-21 10:41:33 +00:00
|
|
|
entries.forEach((entry) => {
|
Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
// FF doesn't seem to support entry.isIntersecting properly,
|
|
|
|
// so we check the intersectionRatio.
|
|
|
|
if (entry.intersectionRatio < 1) {
|
2020-10-21 10:41:33 +00:00
|
|
|
fixableElements.forEach((el) => el.classList.add('js-fixed'));
|
Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
} else {
|
2020-10-21 10:41:33 +00:00
|
|
|
fixableElements.forEach((el) => el.classList.remove('js-fixed'));
|
Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRootMargin() {
|
|
|
|
let rootMarginTop = 72;
|
|
|
|
const { body } = document;
|
|
|
|
|
|
|
|
if (body.classList.contains('toolbar-fixed')) {
|
|
|
|
rootMarginTop -= 39;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
body.classList.contains('toolbar-horizontal') &&
|
|
|
|
body.classList.contains('toolbar-tray-open')
|
|
|
|
) {
|
|
|
|
rootMarginTop -= 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${rootMarginTop}px 0px 0px 0px`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function monitorNavPosition() {
|
|
|
|
const primaryNav = document.querySelector('.site-header');
|
|
|
|
const options = {
|
|
|
|
rootMargin: getRootMargin(),
|
|
|
|
threshold: [0.999, 1],
|
|
|
|
};
|
|
|
|
|
|
|
|
const observer = new IntersectionObserver(
|
|
|
|
toggleDesktopNavVisibility,
|
|
|
|
options,
|
|
|
|
);
|
|
|
|
observer.observe(primaryNav);
|
|
|
|
}
|
|
|
|
|
|
|
|
wideNavButton.addEventListener('click', () => {
|
|
|
|
if (!wideNavIsOpen()) {
|
|
|
|
showWideNav();
|
|
|
|
} else {
|
|
|
|
hideWideNav();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
siteHeaderFixable
|
|
|
|
.querySelector('.site-header__inner')
|
|
|
|
.addEventListener('focusin', showWideNav);
|
|
|
|
|
|
|
|
// If skip link is clicked, ensure that the wide navigation closes so the header will not be covered up.
|
|
|
|
document.querySelector('.skip-link').addEventListener('click', hideWideNav);
|
|
|
|
|
|
|
|
monitorNavPosition();
|
|
|
|
}
|
|
|
|
|
2020-10-21 10:41:33 +00:00
|
|
|
document.addEventListener('keyup', (e) => {
|
Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
if (e.keyCode === 27) {
|
|
|
|
// Close the search form.
|
|
|
|
if (
|
|
|
|
'toggleSearchVisibility' in Drupal.olivero &&
|
|
|
|
'searchIsVisible' in Drupal.olivero &&
|
|
|
|
Drupal.olivero.searchIsVisible()
|
|
|
|
) {
|
|
|
|
Drupal.olivero.toggleSearchVisibility(false);
|
|
|
|
}
|
|
|
|
// Close the wide nav.
|
|
|
|
else {
|
|
|
|
hideWideNav();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})(Drupal);
|