PageSourceSearch

https://www.javascripttutorial.net/wp-content/uploads/essential-op…f4354a9e9c9747ef64c09909493b19bb0f6749ce.js

js javascripttutorial.net collected 2026-10-02 02:24:47 UTC 1,583 bytes, 51 lines download raw bytes

1(function () {
2  // for the site that uses submenu
3  let siteNav = document.querySelector('.site-menu');
4  if (!siteNav) return;
5
6  function closeSubmenuExcept(submenu) {
7    // close other submenus
8    const submenuList = siteNav.querySelectorAll('.sub-menu');
9    // open this and close that
10    if (submenuList) {
11      for (let i = 0; i < submenuList.length; i++) {
12        if (submenuList[i] != submenu) {
13          submenuList[i].classList.remove('show');
14        }
15      }
16    }
17  }
18
19  // click the menu that has a submenu
20  const parentMenuItems = siteNav.querySelectorAll('.menu-item-has-children');
21  if (parentMenuItems) {
22    for (let i = 0; i < parentMenuItems.length; i++) {
23      parentMenuItems[i].addEventListener('click', function (e) {
24        // toggle the current selected submenu
25        const submenu = this.querySelector('.sub-menu');
26        if (submenu) {
27          submenu.classList.toggle('show');
28        }
29        closeSubmenuExcept(submenu);
30      });
31    }
32  }
33
34  // click outside to close the submenu
35  function closeSubmenu(e) {
36    let isClickInside = siteNav.contains(e.target);
37    if (!isClickInside && siteNav.querySelector('.sub-menu.show')) {
38      siteNav.querySelector('.sub-menu.show').classList.remove('show');
39    }
40  }
41  document.addEventListener('click', closeSubmenu, false);
42
43  // prevent jump to # links
44  const links = document.querySelectorAll('.site-menu a[href="#"]');
45
46  links.forEach((link) => {
47    link.addEventListener('click', function (event) {
48      event.preventDefault(); // Prevent default action
49    });
50  });
51})();

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.