PageSourceSearch

https://neighbours-source.cyou/wp-content/themes/fairy/js/navigation.js?ver=1.4.2

js neighbours-source.cyou collected 2026-10-07 20:20:22 UTC 3,049 bytes, 108 lines download raw bytes

1/**
2 * File navigation.js.
3 *
4 * Handles toggling the navigation menu for small screens and enables TAB key
5 * navigation support for dropdown menus.
6 */
7(function () {
8	var container, button, menu, links, i, len;
9
10	container = document.getElementById("site-nav-wrap");
11	nav_tag = document.querySelector(".main-navigation");
12	if (!container) {
13		return;
14	}
15
16	button = container.getElementsByTagName("button")[0];
17	if ("undefined" === typeof button) {
18		return;
19	}
20
21	menu = container.getElementsByTagName("ul")[0];
22
23	// Hide menu toggle button if menu is empty and return early.
24	if ("undefined" === typeof menu) {
25		button.style.display = "none";
26		return;
27	}
28
29	menu.setAttribute("aria-expanded", "false");
30	if (-1 === menu.className.indexOf("nav-menu")) {
31		menu.className += " nav-menu";
32	}
33
34	button.onclick = function () {
35		if (-1 !== nav_tag.className.indexOf("toggled")) {
36			nav_tag.className = nav_tag.className.replace(" toggled", "");
37			button.setAttribute("aria-expanded", "false");
38			menu.setAttribute("aria-expanded", "false");
39		} else {
40			nav_tag.className += " toggled";
41			button.setAttribute("aria-expanded", "true");
42			menu.setAttribute("aria-expanded", "true");
43		}
44	};
45
46	// Get all the link elements within the menu.
47	links = menu.getElementsByTagName("a");
48
49	// Each time a menu link is focused or blurred, toggle focus.
50	for (i = 0, len = links.length; i < len; i++) {
51		links[i].addEventListener("focus", toggleFocus, true);
52		links[i].addEventListener("blur", toggleFocus, true);
53	}
54
55	/**
56	 * Sets or removes .focus class on an element.
57	 */
58	function toggleFocus() {
59		var self = this;
60
61		// Move up through the ancestors of the current link until we hit .nav-menu.
62		while (-1 === self.className.indexOf("nav-menu")) {
63			// On li elements toggle the class .focus.
64			if ("li" === self.tagName.toLowerCase()) {
65				if (-1 !== self.className.indexOf("focus")) {
66					self.className = self.className.replace(" focus", "");
67				} else {
68					self.className += " focus";
69				}
70			}
71
72			self = self.parentElement;
73		}
74	}
75
76	/**
77	 * Toggles `focus` class to allow submenu access on tablets.
78	 */
79	(function (container) {
80		var touchStartFn,
81			i,
82			parentLink = container.querySelectorAll(
83				".menu-item-has-children > a, .page_item_has_children > a"
84			);
85		if ("ontouchstart" in window) {
86			touchStartFn = function (e) {
87				var menuItem = this.parentNode,
88					i;
89				if (!menuItem.classList.contains("focus")) {
90					e.preventDefault();
91					for (i = 0; i < menuItem.parentNode.children.length; ++i) {
92						if (menuItem === menuItem.parentNode.children[i]) {
93							continue;
94						}
95						menuItem.parentNode.children[i].classList.remove("focus");
96					}
97					menuItem.classList.add("focus");
98				} else {
99					menuItem.classList.remove("focus");
100				}
101			};
102
103			for (i = 0; i < parentLink.length; ++i) {
104				parentLink[i].addEventListener("touchstart", touchStartFn, false);
105			}
106		}
107	})(container);
108})();

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.