PageSourceSearch

https://pei.sipametrics.com/nav-toggle.js

js sipametrics.com collected 2026-10-09 17:31:39 UTC 2,115 bytes, 72 lines download raw bytes

1(function () {
2  function ready(fn) {
3    if (document.readyState !== "loading") fn();
4    else document.addEventListener("DOMContentLoaded", fn);
5  }
6
7  ready(function () {
8    var nav = document.querySelector(".nav");
9    if (!nav) return;
10    var toggle = nav.querySelector(".nav-toggle");
11    if (!toggle) return;
12
13    function isMobile() {
14      return window.matchMedia("(max-width: 860px)").matches;
15    }
16
17    function closeMenu() {
18      nav.classList.remove("nav-open");
19      toggle.setAttribute("aria-expanded", "false");
20      nav.querySelectorAll(".nav-item.dropdown-open").forEach(function (item) {
21        item.classList.remove("dropdown-open");
22      });
23    }
24
25    function openMenu() {
26      nav.classList.add("nav-open");
27      toggle.setAttribute("aria-expanded", "true");
28    }
29
30    toggle.addEventListener("click", function () {
31      if (nav.classList.contains("nav-open")) closeMenu();
32      else openMenu();
33    });
34
35    nav.addEventListener("click", function (e) {
36      var link = e.target.closest("a");
37      if (!link) return;
38      var item = link.parentElement;
39      var isDropdownParent =
40        item &&
41        item.classList.contains("nav-item") &&
42        item.classList.contains("has-dropdown") &&
43        item.querySelector(":scope > a") === link;
44
45      if (isMobile() && isDropdownParent) {
46        e.preventDefault();
47        var wasOpen = item.classList.contains("dropdown-open");
48        nav.querySelectorAll(".nav-item.dropdown-open").forEach(function (other) {
49          if (other !== item) other.classList.remove("dropdown-open");
50        });
51        item.classList.toggle("dropdown-open", !wasOpen);
52        return;
53      }
54
55      if (isMobile()) closeMenu();
56    });
57
58    document.addEventListener("click", function (e) {
59      if (isMobile() && nav.classList.contains("nav-open") && !nav.contains(e.target)) {
60        closeMenu();
61      }
62    });
63
64    document.addEventListener("keydown", function (e) {
65      if (e.key === "Escape") closeMenu();
66    });
67
68    window.addEventListener("resize", function () {
69      if (!isMobile()) closeMenu();
70    });
71  });
72})();

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.