@massds/mayflower-assets
Version:
Mayflower Assets
762 lines (732 loc) • 34.1 kB
JavaScript
;
(function () {
window.__forceSmoothScrollPolyfill__ = true;
var script = document.createElement('script');
script.src = "https://unpkg.com/smoothscroll-polyfill@0.4.4/dist/smoothscroll.js";
script.crossOrigin = true;
var element = document.getElementsByTagName('head')[0];
element.appendChild(script);
})();
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
includedLanguages: '',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
document.querySelector('#google_translate_element') !== null ? document.querySelector('#google_translate_element').classList.add('has-rendered') : '';
}
(function () {
var script = document.createElement('script');
script.src = "//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit";
script.async = true;
var element = document.getElementsByTagName('head')[0];
element.appendChild(script);
})();
;
var _focusTrapping = _interopRequireDefault(require("../helpers/focusTrapping.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var hamburgerMenuContainer = document.querySelector(".ma__header__hamburger__nav-container");
if (hamburgerMenuContainer) {
var toggleMenu = function toggleMenu() {
// To prevent null in the original mobile main nav.
if (body.classList.contains("show-menu")) {
// This control the visibility of the dropdown to keyboard and screen reader users while maintaining the show/hide animation effect.
// .toggleAttribute() doesn't work with ios11.
hamburgerMenuContainer.setAttribute("aria-hidden", "");
closeMenu();
setTimeout(function timeoutFunction() {
document.querySelector(".js-header-menu-button").focus();
}, 100);
} else {
hamburgerMenuContainer.removeAttribute("aria-hidden");
openMenu();
}
};
var closeMenu = function closeMenu() {
commonCloseMenuTasks();
menuButton.setAttribute("aria-pressed", "false");
menuButtonText.classList.add("show");
menuButtonTextMobile.classList.add("show");
menuButtonTextClose.classList.remove("show");
// Set focus on the menu button.
setTimeout(function timeoutFunction() {
document.querySelector(".js-header-menu-button").focus();
}, 100);
if (utilityNavOrgsLink && utilityNavOrgsLink.hasAttribute("tabindex")) {
if (utilWideGTranslate.querySelector("a")) {
// Google translate elements aren't rendered screen width under 840px and the object is null.
utilWideGTranslate.querySelector("a").removeAttribute("tabindex");
}
utilityNavOrgsLink.removeAttribute("tabindex");
if (utilityNavToggle) {
utilityNavToggle.removeAttribute("tabindex");
}
document.querySelector(".js-header-search-access-button").removeAttribute("tabindex");
}
if (body.style.position === "fixed") {
// At the same time, the alert needs to be scrolled up to the position again to retain the page elements position.
body.removeAttribute("style");
body.style.position = "relative";
window.scrollTo(0, alertlOffsetPosition);
}
};
var commonCloseMenuTasks = function commonCloseMenuTasks() {
body.classList.remove("show-menu");
if (document.querySelector("html.stickyTOCtmp")) {
document.querySelector("html.stickyTOCtmp").classList.add("stickyTOC");
document.querySelector("html.stickyTOCtmp").classList.remove("stickyTOCtmp");
}
menuButton.setAttribute("aria-expanded", "false");
if (hamburgerMenuContainer.hasAttribute("style")) {
hamburgerMenuContainer.removeAttribute("style");
}
if (searchInput.hasAttribute("autofocus")) {
searchInput.removeAttribute("autofocus");
}
jumpToSearchButton.setAttribute("aria-expanded", "false");
if (menuOverlay) {
menuOverlay.classList.remove("overlay-open");
}
if (alertOverlay) {
alertOverlay.classList.remove("overlay-open");
alertOverlay.removeAttribute("style");
}
};
var openMenu = function openMenu() {
var heightAboveMenuContainer;
var emergencyAlertsHeight;
var alertOffsetAdjusted = 0;
// Set the alert to its offset position in the window to prevent the page to shift as the menu opens.
var lockPage = function lockPage() {
if (document.querySelector(".ma__emergency-alerts")) {
document.querySelector("body").style.top = "-".concat(alertlOffsetPosition, "px");
} else {
document.querySelector("body").style.top = 0;
}
heightAboveMenuContainer = hamburgerMenuContainer.getBoundingClientRect().top;
};
if (document.querySelector("html.stickyTOC")) {
document.querySelector("html.stickyTOC").classList.add("stickyTOCtmp");
document.querySelector("html.stickyTOC").classList.remove("stickyTOC");
}
// Start open menu tasks.
body.classList.add("show-menu");
menuButton.setAttribute("aria-expanded", "true");
menuButtonText.classList.remove("show");
menuButtonTextMobile.classList.remove("show");
menuButtonTextClose.classList.add("show");
jumpToSearchButton.setAttribute("aria-expanded", "true");
menuButton.setAttribute("aria-pressed", "true");
var alertsHeader = document.querySelector(".ma__emergency-alerts__header");
document.querySelector("body").style.position = "fixed";
// Set buttons between menu button and hamburger menu unfocusable to set focus on the first focusable item in the menu at next tabbing.
if (utilWideGTranslate.querySelector("a") && body.clientWidth > 840) {
// Google translate elements aren't rendered screen width under 840px, and the object is null.
utilWideGTranslate.querySelector("a").setAttribute("tabindex", "-1");
}
if (utilityNavOrgsLink) {
utilityNavOrgsLink.setAttribute("tabindex", "-1");
}
if (utilityNavToggle) {
utilityNavToggle.setAttribute("tabindex", "-1");
}
if (alertsHeader !== null) {
var emergencyAlerts = document.querySelector(".ma__emergency-alerts");
emergencyAlertsHeight = emergencyAlerts.offsetHeight;
alertOffsetAdjusted = alertsHeader.offsetHeight / 2;
alertlOffsetPosition = emergencyAlertsHeight - alertOffsetAdjusted;
lockPage();
var hamburgerNavOffset = document.querySelector(".ma__header__hamburger__nav").offsetHeight;
heightAboveMenuContainer = alertOffsetAdjusted + hamburgerNavOffset;
hamburgerMenuContainer.style.height = "calc(100vh - ".concat(heightAboveMenuContainer, "px)");
}
if (menuOverlay) {
var overlayOffset = heightAboveMenuContainer;
if (width > 840) {
overlayOffset = overlayOffset - 1;
}
menuOverlay.classList.add("overlay-open");
}
if (alertOverlay) {
if (document.querySelector(".ma__emergency-alerts")) {
alertOverlay.classList.add("overlay-open");
}
}
};
var jumpToSearch = function jumpToSearch(e) {
if (body.classList.contains("show-menu")) {
// This control the visibility of the dropdown to keyboard and screen reader users while maintaining the show/hide animation effect.
hamburgerMenuContainer.setAttribute("aria-hidden", "");
searchInput.focus();
} else {
hamburgerMenuContainer.removeAttribute("aria-hidden");
openMenu();
setTimeout(function timeoutFunction() {
jumpToSearchButton.setAttribute("aria-pressed", "true");
searchInput.setAttribute("autofocus", "");
searchInput.focus();
}, 200);
}
};
var anotherCloseSubMenus = function anotherCloseSubMenus(item) {
menuItems.forEach(function (li) {
if (item !== li && li.classList.contains("submenu-open")) {
li.classList.remove("submenu-open");
li.querySelector(".js-main-nav-hamburger__top-link").setAttribute("aria-expanded", "false");
li.style.pointerEvents = "none";
/** Slide up. */
li.querySelector(".js-main-nav-hamburger-content").style.height = "0";
li.querySelector(".js-main-nav-hamburger__container").style.opacity = "0";
setTimeout(function timeoutFunction() {
li.removeAttribute("style");
li.querySelector(".js-main-nav-hamburger-content").classList.add("is-closed");
}, 500);
}
});
}; // Close menu when utility nav is clicked
var openNarrowUtilContent = function openNarrowUtilContent(utilNarrowButton) {
var utilNarrowContent = utilNarrowButton && utilNarrowButton.nextElementSibling;
var utilNarrowContainer = utilNarrowContent && utilNarrowContent.querySelector(".ma__utility-nav__container");
var utilItem = utilNarrowButton && utilNarrowButton.parentElement;
utilNarrowButton.setAttribute("aria-expanded", "true");
utilNarrowContent.removeAttribute("aria-hidden");
utilNarrowContainer.style.pointerEvents = "none";
/** Slide down. */
utilNarrowContainer.removeAttribute("style");
/** Show the content. */
utilNarrowContent.classList.remove("is-closed");
utilNarrowContent.style.maxHeight = "auto";
// Add submenu-open class to list item
utilItem.classList.add("subutil-open");
/** Get the computed height of the content. */
var contentHeight = utilNarrowContent.querySelector(".ma__utility-nav__content-body").clientHeight + "px";
/** Set the height of the submenu as 0px, */
/** so we can trigger the slide down animation. */
utilNarrowContent.style.maxHeight = "0";
utilNarrowContent.style.Height = "0";
// These height settings display the bottom border of the parent li at the correct spot.
utilNarrowContent.style.height = contentHeight;
utilNarrowContainer.style.height = contentHeight;
utilNarrowContent.style.maxHeight = contentHeight;
utilNarrowContainer.style.opacity = "1";
};
var closeNarrowUtilContent = function closeNarrowUtilContent(utilNarrowButton) {
var utilNarrowContent = utilNarrowButton && utilNarrowButton.nextElementSibling;
var utilNarrowContainer = utilNarrowContent && utilNarrowContent.querySelector(".ma__utility-nav__container");
var utilItem = utilNarrowButton && utilNarrowButton.parentElement;
if (utilNarrowContent) {
utilNarrowButton.setAttribute("aria-expanded", "false");
utilNarrowContent.setAttribute("aria-hidden", "true");
utilNarrowContainer.style.pointerEvents = "none";
utilNarrowContainer.removeAttribute("style");
utilNarrowContent.style.maxHeight = "0";
utilNarrowContainer.style.opacity = "0";
utilNarrowContent.classList.add("is-closed");
utilItem.classList.remove("subutil-open");
}
};
var closeAllNarrowUtilContent = function closeAllNarrowUtilContent() {
utilNarrowButtons.forEach(function (utilNarrowButton) {
closeNarrowUtilContent(utilNarrowButton);
});
}; // ** Utility keydown events
// ** End util nav
var closeSubMenu = function closeSubMenu() {
var openSubMenu = document.querySelector(".submenu-open");
if (openSubMenu) {
var openSubMenuButton = openSubMenu.querySelector(".js-main-nav-hamburger__top-link");
var openSubMenuContent = openSubMenu.querySelector(".js-main-nav-hamburger-content");
var openSubMenuContainer = openSubMenu.querySelector(".js-main-nav-hamburger__container");
openSubMenuButton.setAttribute("aria-expanded", "false");
openSubMenuContent.style.height = "0";
openSubMenuContainer.style.opacity = "0";
openSubMenuContent.classList.add("is-closed");
openSubMenu.removeAttribute("style");
openSubMenu.classList.remove("submenu-open");
}
}; // Target iOS Safari versions less than 11 to handle issues that cannot be targeted
// with behavior detection due to either buggy or idiosyncratic browser implementation
// issues addressed in later major versions.
var selectTopClickableItems = function selectTopClickableItems(windowWidth) {
topLevelClickableItems = "";
if (windowWidth > 840) {
topLevelClickableItems = hamburgerMenuContainer.querySelectorAll(".ma__header__hamburger__main-nav .ma__main__hamburger-nav__top-link");
}
if (windowWidth < 841) {
topLevelClickableItems = hamburgerMenuContainer.querySelectorAll(".ma__main__hamburger-nav__top-link, .goog-te-gadget a, .ma__utility-nav__link");
}
if (windowWidth < 621) {
// mobile
topLevelClickableItems = hamburgerMenuContainer.querySelectorAll(".ma__site-logo a, .ma__header-search__input, .ma__button-search--secondary, .ma__header__hamburger__logo--mobile a, .ma__header-search__input, .ma__main__hamburger-nav__top-link, .goog-te-gadget a, .ma__utility-nav__link");
}
// Arrow keyboard navigation in the top level clickable elements.
var lastTopItemIndex = topLevelClickableItems.length - 1;
// Here, manage navigating items on the top level to cover all clickable elements.
// Managing opening sub container and setting focus with up/down arrow keys are managed separately.
topLevelClickableItems.forEach(function (link, index) {
link.addEventListener("keydown", function (e) {
if (e.key === "ArrowRight" || e.code === "ArrowRight") {
// forward
var targetIndex = index + 1;
var nextItem = topLevelClickableItems[targetIndex];
if (index === lastTopItemIndex) {
topLevelClickableItems[0].focus();
} else {
nextItem.focus();
}
}
if (e.key === "ArrowLeft" || e.code === "ArrowLeft") {
// backward
var _targetIndex2 = index - 1;
var priorItem = topLevelClickableItems[_targetIndex2];
if (index === 0) {
topLevelClickableItems[lastTopItemIndex].focus();
} else {
priorItem.focus();
}
}
});
});
}; // Keyboard navigation with Google Translate widget
// Set focus on the (closest/visible) Google Translate button whether it's on the blue bar or in the hamburger menu.
var osInfo = navigator.appVersion;
var body = document.querySelector("body");
var width = body.clientWidth;
var alertlOffsetPosition;
var menuOverlay = document.querySelector(".menu-overlay");
var alertOverlay = document.querySelector(".alert-overlay");
var menuButton = document.querySelector(".js-header-menu-button");
var menuButtonText = document.querySelector(".js-header__menu-text");
var menuButtonTextMobile = document.querySelector(".js-header__menu-text--mobile");
var menuButtonTextClose = document.querySelector(".js-header__menu-text--close");
var jumpToSearchButton = document.querySelector(".js-header-search-access-button");
var searchInput = document.querySelector(".ma__header__hamburger__nav-container .ma__header-search__input");
var menuItems = document.querySelectorAll(".js-main-nav-hamburger-toggle");
var utilityNavToggle = document.querySelector(".js-utility-nav--wide .ma__utility-nav__item .js-util-nav-toggle");
var utilNavWide = document.querySelector(".js-utility-nav--wide");
var utilityNavOrgsLink = document.querySelector(".js-utility-nav--wide .ma__utility-nav__item .direct-link");
var utilWideGTranslate = document.querySelector(".js-utility-nav--wide .ma__utility-nav__item .ma__utility-nav__translate");
// Define all top level clickable elements with current window width.
var topLevelClickableItems;
window.addEventListener("DOMContentLoaded", function (e) {
setTimeout(function timeoutFunction() {
// This prevents GT elements get null.
selectTopClickableItems(width);
}, 1000);
});
window.addEventListener("resize", function (e) {
selectTopClickableItems(body.clientWidth);
});
// Add a label for the utility nav UL on non-home pages in desktop.
if (width > 840) {
var headerClass = document.querySelector("header").classList;
if (!headerClass.contains("ma__header__mixed")) {
utilNavWide.querySelector(".ma__utility-nav__items").setAttribute("aria-label", "Language options and quick access links");
}
}
if (menuButton !== null) {
// Open and close the menu
menuButton.addEventListener("click", function (event) {
event.preventDefault();
// For Safari, this ensures to move focus to the menu content.
if (osInfo.indexOf("Safari") !== -1) {
menuButton.focus();
}
toggleMenu();
});
// Skip the magnifier icon button (skip to search)
var logoLink = document.querySelector(".ma__header__hamburger__nav-container .ma__header__hamburger__logo--mobile a");
if (logoLink) {
menuButton.addEventListener("keydown", function (e) {
if (e.key === "Tab" && !(e.shiftKey && e.key === "Tab") || e.code === "Tab" && !(e.shiftKey && e.code === "Tab")) {
if (menuButton.getAttribute("aria-expanded") === "true") {
setTimeout(function timeoutFunction() {
logoLink.focus();
}, 100);
}
}
});
logoLink.addEventListener("keydown", function (e) {
if (e.shiftKey && e.key === "Tab" || e.shiftKey && e.code === "Tab") {
setTimeout(function timeoutFunction() {
menuButton.focus();
}, 100);
}
});
}
document.addEventListener("keydown", function (e) {
// ESC to close menus.
// 'e.key === "Esc"' is necessary for IE11.
if (e.key === "Escape" || e.key === "Esc" || e.code === "Escape") {
// Google Translage in the hamburger menu
if (document.querySelector(".ma__header__hamburger__utility-nav--narrow .ma__utility-nav__translate #google_translate_element a") === document.activeElement) {
closeMenu();
}
var openSubmenu = document.querySelector(".submenu-open .js-main-nav-hamburger__top-link");
var openTopMenuUnit = document.querySelector(".submenu-open");
// Main nav elements
if (!openTopMenuUnit || openSubmenu !== document.activeElement) {
// To prevent to set focus on another top menu button with open submenu.
var menus = document.querySelectorAll(".ma__main__hamburger-nav__top-link");
for (var i = 0; i < menus.length; i++) {
if (menus[i] === document.activeElement) {
closeMenu();
}
}
// Set focus on its parent top menu button.
var openSubmenuItems = document.querySelectorAll(".submenu-open .js-main-nav-hamburger-content:not(is-closed) .js-main-nav-hamburger__link");
for (var _i = 0; _i < openSubmenuItems.length; _i++) {
if (openSubmenuItems[_i] === document.activeElement) {
openSubmenu.focus();
// Close sub menu
openTopMenuUnit.classList.remove("submenu-open");
openTopMenuUnit.querySelector(".js-main-nav-hamburger__top-link").setAttribute("aria-expanded", "false");
openTopMenuUnit.style.pointerEvents = "none";
/** Slide up. */
openTopMenuUnit.querySelector(".js-main-nav-hamburger-content").style.height = "0";
openTopMenuUnit.querySelector(".js-main-nav-hamburger__container").style.opacity = "0";
setTimeout(function timeoutFunction() {
openTopMenuUnit.removeAttribute("style");
openTopMenuUnit.querySelector(".js-main-nav-hamburger-content").classList.add("is-closed");
}, 500);
}
}
} else {
closeMenu();
}
}
});
// Arrow keyboard navigation in the sub menu.
var submenuLinks = document.querySelectorAll(".js-main-nav-hamburger__link");
submenuLinks.forEach(function (link) {
link.addEventListener("keydown", function (e) {
var targetParent = e.target.closest(".js-main-nav-hamburger__subitem");
if (e.key === "ArrowDown" || e.code === "ArrowDown") {
if (targetParent.nextElementSibling) {
targetParent.nextElementSibling.querySelector("a").focus();
} else {
// Set focus on the first sibling submenu item link.
document.querySelector(".js-main-nav-hamburger-content:not(.is-closed) .js-main-nav-hamburger__subitem:first-of-type a").focus();
}
}
if (e.key === "ArrowUp" || e.code === "ArrowUp") {
if (targetParent.previousElementSibling) {
targetParent.previousElementSibling.querySelector("a").focus();
} else {
// Set focus on the last sibling submenu item link.
document.querySelector(".js-main-nav-hamburger-content:not(.is-closed) .js-main-nav-hamburger__subitem:last-of-type a").focus();
}
}
});
});
}
// hamburger menu keyboard nav
// Tabbing through all links and buttons in the hamburger menu container and the menu button.
document.addEventListener("keydown", function (e) {
if (menuButton.getAttribute("aria-expanded") === "true") {
(0, _focusTrapping["default"])({
focusableSelectors: "[role='menuitem'], .js-utility-nav--narrow .ma__utility-nav__item .ma__utility-nav__link, .ma__utility-nav__item .ma__utility-nav__container a",
closeButtonSelector: ".js-header-menu-button",
modalSelector: ".ma__header__hamburger__nav-container",
keyEvent: e
});
}
});
if (jumpToSearchButton !== null) {
jumpToSearchButton.addEventListener("click", function (e) {
e.preventDefault();
jumpToSearch();
});
}
if (utilNavWide !== null && body.classList.contains("show-menu")) {
closeMenu();
}
// Close and reset menu on overlay click
if (null !== menuOverlay) {
menuOverlay.addEventListener("click", function () {
closeMenu();
});
}
if (alertOverlay !== null) {
alertOverlay.addEventListener("click", function () {
closeMenu();
});
}
var debouncer;
window.addEventListener("resize", function () {
clearTimeout(debouncer);
var osInfo = navigator.appVersion;
// On Android devices resize event is triggered when keyboard appears
// and it closes the menu.
if (osInfo.indexOf("Android") === -1 && osInfo.indexOf("iPhone") === -1) {
debouncer = setTimeout(function () {
closeMenu();
}, 100);
}
});
// ** Utility nav on mobile
var utilNarrowNav = document.querySelector(".js-utility-nav--narrow");
var utilNarrowButtons = document.querySelectorAll(".js-utility-nav--narrow button.js-util-nav-toggle");
utilNarrowButtons.forEach(function (utilNarrowButton) {
var utilNarrowContent = utilNarrowButton && utilNarrowButton.nextElementSibling;
var utilNarrowContainer = utilNarrowContent && utilNarrowContent.querySelector(".ma__utility-nav__container");
utilNarrowContent.style.maxHeight = "0";
utilNarrowContainer.style.opacity = "0";
["click", "keyup"].forEach(function (e) {
utilNarrowButton.addEventListener(e, function (e) {
if (utilNarrowContent.classList.contains("is-closed")) {
if (e.type === "click" || e.key === "ArrowDown" || e.key === "ArrowUp") {
// TO OPEN
closeSubMenu();
closeAllNarrowUtilContent();
openNarrowUtilContent(utilNarrowButton);
}
} else {
if (e.type === "click") {
closeNarrowUtilContent(utilNarrowButton);
}
}
if (e.type === "keyup") {
var clickableItems = utilNarrowContainer && utilNarrowContainer.querySelectorAll(".js-util-nav-content a.js-clickable-link");
if (e.key === "ArrowDown" || e.code === "ArrowDown") {
clickableItems[0] && clickableItems[0].focus();
}
if (e.key === "ArrowUp" || e.code === "ArrowUp") {
var lastItemIndex = clickableItems.length - 1;
clickableItems[lastItemIndex] && clickableItems[lastItemIndex].focus();
}
}
}, false);
});
});
utilNarrowNav.addEventListener("keydown", function (e) {
// Util nav escape
if (e.key === "Escape" || e.code === "Escape") {
if (utilNarrowNav) {
var narrowUtilNavContentActive = document.querySelector('.js-utility-nav--narrow .subutil-open');
// if a util sub nav is open
if (narrowUtilNavContentActive) {
// find all the interactive elements in the open sub nav
var utilNavContentLinks = narrowUtilNavContentActive.querySelectorAll("button, [href], input");
for (var i = 0; i < utilNavContentLinks.length; i++) {
if (utilNavContentLinks[i].innerText === document.activeElement.innerText) {
// close the open sub nav
var thisUtilButton = narrowUtilNavContentActive.querySelector(".js-util-nav-toggle");
if (!thisUtilButton) return;
closeNarrowUtilContent(thisUtilButton);
thisUtilButton.focus();
}
}
// if no util sub nav is open
} else {
// find all toggle buttons in the util nav
var narrowNavItems = utilNarrowNav.querySelectorAll(".js-util-nav-toggle");
for (var _i2 = 0; _i2 < narrowNavItems.length; _i2++) {
if (narrowNavItems[_i2].innerText === document.activeElement.innerText) {
// close the sub nav that is being focused on
var _thisUtilButton = narrowNavItems[_i2].querySelector(".js-util-nav-toggle");
if (!_thisUtilButton) return;
closeNarrowUtilContent(_thisUtilButton);
// close the hamburger menu
closeMenu();
}
}
}
}
}
});
var narrowUtilContentLinks = document.querySelectorAll(".js-utility-nav--narrow .js-util-nav-content a.js-clickable-link");
var lastIndex = narrowUtilContentLinks.length - 1;
narrowUtilContentLinks.forEach(function (link, i) {
link.addEventListener("keydown", function (e) {
if (e.key === "ArrowDown" || e.code === "ArrowDown") {
if (e.target === narrowUtilContentLinks[i]) {
if (e.target === narrowUtilContentLinks[lastIndex]) {
i = 0;
} else {
i++;
}
} else {
if (e.target === narrowUtilContentLinks[lastIndex]) {
i = 0;
} else {
var targetIndex;
for (var index = 0; index < narrowUtilContentLinks.length; index++) {
if (e.target === narrowUtilContentLinks[index]) {
targetIndex = index;
}
}
i = targetIndex;
i++;
}
}
narrowUtilContentLinks[i].focus();
}
if (e.key === "ArrowUp" || e.code === "ArrowUp") {
if (e.target === narrowUtilContentLinks[i]) {
if (e.target === narrowUtilContentLinks[0]) {
i = lastIndex;
} else {
i--;
}
} else {
if (e.target === narrowUtilContentLinks[0]) {
i = lastIndex;
} else {
var _targetIndex;
for (var _index = lastIndex; _index > -1; _index--) {
if (e.target === narrowUtilContentLinks[_index]) {
_targetIndex = _index;
}
}
i = _targetIndex;
i--;
}
}
narrowUtilContentLinks[i].focus();
}
});
});
if (osInfo.indexOf("Safari") !== -1) {
osInfo.split(" ").forEach(function (splitVar) {
if (splitVar.length > 0 && splitVar.indexOf("Version/", 0) !== false) {
var version = splitVar.match(/\d+/);
if (version !== null && version[0] < 11) {
body.classList.add("ios-safari-less-than-11");
}
}
});
}
menuItems.forEach(function (item) {
var itemButton = item.querySelector(".js-main-nav-hamburger__top-link");
var subMenu = item.querySelector(".js-main-nav-hamburger-content");
var subItems = subMenu.querySelector(".js-main-nav-hamburger__container");
subItems.style.opacity = "0";
itemButton.addEventListener("click", function (e) {
expandSubMenuContainer();
e.target.focus();
});
itemButton.addEventListener("keydown", function (e) {
if (e.key === "ArrowDown" || e.code === "ArrowDown") {
if (!e.target.parentElement.classList.contains("submenu-open")) {
expandSubMenuContainer();
}
e.target.closest(".js-main-nav-hamburger-toggle").querySelector(".js-main-nav-hamburger__subitem:first-child .js-main-nav-hamburger__link").focus();
}
if (e.key === "ArrowUp" || e.code === "ArrowUp") {
if (!e.target.parentElement.classList.contains("submenu-open")) {
expandSubMenuContainer();
}
e.target.closest(".js-main-nav-hamburger-toggle").querySelector(".js-main-nav-hamburger__subitem:last-child .js-main-nav-hamburger__link").focus();
}
});
function expandSubMenuContainer() {
anotherCloseSubMenus(item);
if (item.classList.contains("submenu-open")) {
item.classList.remove("submenu-open");
itemButton.setAttribute("aria-expanded", "false");
item.style.pointerEvents = "none";
setTimeout(function timeoutFunction() {
item.removeAttribute("style");
}, 700);
} else {
item.classList.add("submenu-open");
itemButton.setAttribute("aria-expanded", "true");
item.style.pointerEvents = "none";
setTimeout(function timeoutFunction() {
item.removeAttribute("style");
}, 500);
}
if (item.querySelector(".js-main-nav-hamburger-content").classList.contains("is-closed")) {
/** Show the subMenu. */
item.querySelector(".js-main-nav-hamburger-content").classList.remove("is-closed");
item.querySelector(".js-main-nav-hamburger-content").style.height = "auto";
/** Get the computed height of the subMenu. */
var height = item.querySelector(".js-main-nav-hamburger-content").clientHeight + "px";
/** Set the height of the submenu as 0px, */
/** so we can trigger the slide down animation. */
item.querySelector(".js-main-nav-hamburger-content").style.height = "0";
setTimeout(function timeoutFunction() {
item.querySelector(".js-main-nav-hamburger-content").style.height = height;
if (!body.classList.contains("ios-safari-less-than-11")) {
item.scrollIntoView({
behavior: "smooth",
block: "start",
inline: "start"
});
}
subItems.style.opacity = "1";
}, 500);
/** Close Utility menu content when a sub menu is open. */
if (width < 840) {
closeAllNarrowUtilContent();
}
} else {
item.querySelector(".js-main-nav-hamburger-content").style.height = "0";
subItems.style.opacity = "0";
// Set a little bit of delay to run
// The open/close submenu animation is CSS.
// Unable to confirm the completion of the animation in JS.
// Unable to use callback in this case.
setTimeout(function timeoutFunction() {
item.querySelector(".js-main-nav-hamburger-content").classList.add("is-closed");
}, 500);
}
}
});
setTimeout(function timeoutFunction() {
// This prevents GT elements get null.
var gTranslateButtons = document.querySelectorAll(".ma__utility-nav__translate #google_translate_element a");
var gTranslateOptionContainer = document.querySelector("iframe.goog-te-menu-frame.skiptranslate");
// Hide "+" symbol from screen readers.
var hamburgerGTSymbol = utilNarrowNav.querySelector(".ma__utility-nav__translate #google_translate_element a span:nth-of-type(3)");
if (hamburgerGTSymbol) {
hamburgerGTSymbol.setAttribute("aria-hidden", "true");
}
if (gTranslateOptionContainer) {
gTranslateOptionContainer.contentWindow.document.addEventListener("keydown", function (e) {
var key = e.code ? e.code : e.key;
var firstGTOption = gTranslateOptionContainer.contentWindow.document.querySelector("a.goog-te-menu2-item-selected");
var lastGTOption = gTranslateOptionContainer.contentWindow.document.querySelector("td:last-child a.goog-te-menu2-item:last-child");
var currentFocusInIframe = gTranslateOptionContainer.contentWindow.document.activeElement;
// Set focus on the menu button when SHIFT + TAB are hit on the first Google Translate focusable element.
if (currentFocusInIframe === firstGTOption && e.shiftKey && key === "Tab") {
e.preventDefault();
gTranslateButtons[0].focus();
}
// Set focus on the menu button when TAB is hit on the last Google Translate focusable element.
if (currentFocusInIframe === lastGTOption && key === "Tab") {
e.preventDefault();
gTranslateButtons[0].focus();
}
// Close the container with ESC and set focus on the menu button.
if (key === "Escape" || key === "Esc") {
gTranslateOptionContainer.classList.remove("show");
gTranslateButtons[0].focus();
}
});
}
}, 1000); // When it's less than 1000, the iframe is null in full screen display.
}
;
// // ****** Menu button ******
var mobileMenuButton = document.querySelector(".js-header-menu-button");
var mobileFeedbackButton = document.querySelector(".ma__fixed-feedback-button");
var mobileJumpToSearchButton = document.querySelector(".js-header-search-access-button");
if (mobileMenuButton !== null) {
mobileMenuButton.addEventListener("click", function (event) {
event.preventDefault();
// Toggle mobile menu.
if (window.innerWidth < 841 && document.querySelector(".ma__header")) {
toggleMobileMenu();
}
});
}
function toggleMobileMenu() {
var body = document.querySelector("body");
if (body.classList.contains("show-menu")) {
body.classList.remove("show-menu");
} else {
body.classList.add("show-menu");
}
}