PageSourceSearch

https://www.njsba.org/wp-content/themes/njsba/static/js/main-menu-init.js?ver=1737786429

js njsba.org collected 2026-10-01 11:33:09 UTC 2,589 bytes, 70 lines download raw bytes

1  // init main menu and search
2  document.addEventListener('DOMContentLoaded', function() {
3
4    const menu = document.querySelector('.mainmenu');
5    const mega   = document.querySelector('.mega-menu');
6    const search = document.querySelector('#searchform');
7    const searchButtons = document.querySelectorAll('.search-toggle');
8    const navToggle = document.querySelector('.navbar-toggler');
9    const mobileMenu = document.querySelector('.mainmenu-mobile');
10    const mainNavMobile = document.querySelector('#nav-main-mobile');
11
12    if ( menu ) {
13      const megaMenu = new MegaMenu( menu, mobileMenu, mega );
14      megaMenu.init();
15    }
16    const searchForm = new SearchForm( search,searchButtons );
17    searchForm.init();
18
19    navToggle.addEventListener('click', (e) => {
20      let expanded = e.target.getAttribute('aria-expanded') === 'true' ? true : false;
21      mainNavMobile.classList.toggle('mobile-nav-active');
22      navToggle.setAttribute('aria-expanded', !expanded);
23      document.documentElement.classList.toggle('kill-scroll');
24    });
25
26    [menu,mega,mobileMenu,mainNavMobile].forEach(el => {
27      el.querySelectorAll('a').forEach(link => {
28        if ( link.href === '#' ) link.removeAttribute('href');
29      });
30    });
31
32// Dyanamic URL replacement in menu items
33     function sanitizeUrl(url) {
34      // Create an anchor element to use the browser's built-in URL parser
35      var a = document.createElement('a');
36      a.href = url;
37
38      // Use only the essential parts of the URL (protocol, hostname, pathname, and search parameters)
39      var sanitizedUrl = a.protocol + '//' + a.hostname + a.pathname + a.search;
40
41      // Return the sanitized URL
42      return sanitizedUrl;
43    }
44
45    function replaceMenuItemUrl(selector, searchString) {
46      // Get the current URL
47      var currentUrl = window.location.href;
48
49      // Sanitize the current URL
50      var sanitizedUrl = sanitizeUrl(currentUrl);
51
52      // Find the menu item(s) using the selector
53      $(selector).each(function() {
54        // Get the current text or HTML of the menu item
55        var itemContent = $(this).html();
56
57        // Replace the search string with the sanitized URL
58        var updatedContent = itemContent.replace(searchString, sanitizedUrl);
59
60        // Update the menu item with the new content
61        $(this).html(updatedContent);
62      });
63    }
64
65    // Call the function to replace the string in the menu item
66    // Example: Replace "old-url" with the current sanitized URL in menu items with class "menu-item"
67    replaceMenuItemUrl('.member-login', '%page%');
68
69
70  });

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.