1(function ($) { 2 // Global variables 3 var mobileMenuInitialized = false; // Flag that mobile menu is already set up 4 5 // Window Load = Entire page including the DOM is ready 6 $(window).load(function () { 7 setupMobileMenu(); 8 }); 9 10 // On window resize 11 $(window).resize(function () { 12 setupMobileMenu(); 13 }); 14 15 // Initialize mobile menu based on body class 16 function setupMobileMenu() { 17 if (mobileMenuInitialized === true || !isMobileScreen()) { 18 // Only set up once, and only if on a mobile screen size 19 return; 20 } 21 22 var bodyClass = $("body").attr("class"); 23 var isAccordionMenu = bodyClass.includes("mobile-menu-accordion"); 24 25 // Copy each top-level menu item that contains a sub-menu into the sub-menu 26 $("#mobile-navigation .menu-item-has-children").each(function () { 27 var linkElement = $(this).children("a"); 28 var linkElementText = isAccordionMenu ? "Overview" : $(linkElement).text(); 29 var linkElementURL = $(linkElement).attr("href"); 30 var linkElementSubMenu = $(linkElement).next(".sub-menu"); 31 32 // If the link is not a "no-sub" link, and the link is not #, create a list item and link within sub-menu 33 if (!$(this).hasClass("no-sub") && linkElementURL !== "#") { 34 // Create list item and link within sub-menu 35 $(linkElementSubMenu).prepend( 36 '<li class="menu-item hide-for-large"><a href="' + 37 linkElementURL + 38 '">' + 39 linkElementText + 40 "</a></li>" 41 ); 42 } 43 44 // Label the link to indicate it will open a sub-menu 45 $(linkElement).attr("aria-label", "Open " + linkElementText + " sub-menu"); 46 }); 47 48 // Insert "Back" button if using paged style 49 if (!isAccordionMenu) { 50 $("#mobile-navigation .sub-menu").prepend( 51 '<li class="mobile-navigation-previous"><button class="alt-01"><i class="fas fa-arrow-left small-margin-right"></i>Back</button></li>' 52 ); 53 } 54 55 // Create inner wrapper for flex layout 56 $("#mobile-navigation > ul").wrap('<div id="mobile-navigation-inner"></div>'); 57 58 $('<div id="mobile-navigation-top"></div>').prependTo("#mobile-navigation-inner"); 59 $('<div id="mobile-navigation-search"></div>').appendTo("#mobile-navigation-inner"); 60 61 // Move mobile navigation top into place 62 $("#mobile-navigation-top-inner").detach().appendTo("#mobile-navigation-top"); 63 64 // Move mobile navigation search into place 65 $("#mobile-navigation-search-inner").detach().appendTo("#mobile-navigation-search"); 66 67 console.log("Initialized mobile menu JS"); 68 69 mobileMenuInitialized = true; 70 } 71 72 // Mobile menu: Open and close 73 $(".mobile-menu-toggle").on("click", function () { 74 toggleMobileMenu(); 75 }); 76 77 // Allow any clicks on container to close an open mobile menu 78 $("#container").on("click", function () { 79 if ($(this).isActive()) { 80 toggleMobileMenu(); 81 } 82 }); 83 84 // Opens or closes mobile menu, changing necessary classes 85 function toggleMobileMenu() { 86 $("#mobile-navigation").toggleClass("active"); 87 $("#mobile-navigation li").removeClass("sub-menu-open"); 88 89 // Prevent/allow body scrolling when mobile menu is open/closed 90 if ($("#mobile-navigation").hasClass("active")) { 91 $("body").addClass("mobile-menu-open"); 92 } else { 93 $("body").removeClass("mobile-menu-open"); 94 } 95 96 setTimeout(function () { 97 $("#container").toggleClass("active"); 98 }, 100); 99 } 100 101 // Mobile menu interaction: Back button paging controls 102 // Because the buttons are created after page load, events handled by delegation 103 $("#mobile-navigation").on("click", ".mobile-navigation-previous button", function (e) { 104 e.preventDefault(); 105 $(this).closest(".menu-item-has-children").removeClass("sub-menu-open"); 106 }); 107 108 // Mobile navigation links with children do not directly link to the landing page, but activate the sub-menu 109 $("#mobile-navigation .menu-item-has-children > a").on("click", function (e) { 110 e.preventDefault(); 111 $(this).next(".mobile-navigation-next").trigger("click"); 112 $(this).parent().toggleClass("sub-menu-open"); 113 }); 114})(jQuery);
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.