PageSourceSearch

https://countyconnection.com/wp-content/themes/cccta/js/navigation.js?ver=1.0.4

js countyconnection.com collected 2026-09-24 09:29:06 UTC 3,429 bytes, 128 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 */
7jQuery(function ($) {
8	var container, button, menu, links, i, len;
9
10	container = document.getElementById('site-navigation');
11	if (!container) {
12		return;
13	}
14
15	$('.page-item > a', container).click(function (event) {
16		var menu = $(this).parents('.page-item');
17		if (menu.data('menu')) {
18			event.preventDefault();
19
20			if ($(menu).hasClass('active')) {
21				// Close open menu
22				$(menu).removeClass('active');
23				$('.submenu[data-menu="' + menu.data('menu') + '"]').slideUp();
24
25				return;
26			}
27			$(menu).addClass('active').siblings().removeClass('active');
28
29			$('.submenu').slideUp();
30			$('.submenu[data-menu="' + menu.data('menu') + '"]').slideDown();
31		}
32	})
33
34	button = container.getElementsByTagName('button')[0];
35	if ('undefined' === typeof button) {
36		return;
37	}
38
39	menu = container.getElementsByTagName('ul')[0];
40
41	// Hide menu toggle button if menu is empty and return early.
42	if ('undefined' === typeof menu) {
43		button.style.display = 'none';
44		return;
45	}
46
47	menu.setAttribute('aria-expanded', 'false');
48	if (-1 === menu.className.indexOf('nav-menu')) {
49		menu.className += ' nav-menu';
50	}
51
52	button.onclick = function () {
53		if ($(container).hasClass('toggled')) {
54			$(container).removeClass('toggled');
55			$(button).attr('aria-expanded', 'false');
56			$(menu).attr('aria-expanded', 'false');
57			$('.main-navigation .nav-menu').slideUp();
58		} else {
59			$(container).addClass('toggled');
60			$(button).attr('aria-expanded', 'true');
61			$(menu).attr('aria-expanded', 'true');
62			$('.main-navigation .nav-menu').slideDown();
63		}
64	};
65
66	// Get all the link elements within the menu.
67	links = menu.getElementsByTagName('a');
68
69	// Each time a menu link is focused or blurred, toggle focus.
70	for (i = 0, len = links.length; i < len; i++) {
71		links[i].addEventListener('focus', toggleFocus, true);
72		links[i].addEventListener('blur', toggleFocus, true);
73	}
74
75	/**
76	 * Sets or removes .focus class on an element.
77	 */
78	function toggleFocus() {
79		var self = this;
80
81		// Move up through the ancestors of the current link until we hit .nav-menu.
82		while (-1 === self.className.indexOf('nav-menu')) {
83
84			// On li elements toggle the class .focus.
85			if ('li' === self.tagName.toLowerCase()) {
86				if (-1 !== self.className.indexOf('focus')) {
87					self.className = self.className.replace(' focus', '');
88				} else {
89					self.className += ' focus';
90				}
91			}
92
93			self = self.parentElement;
94		}
95	}
96
97	/**
98	 * Toggles `focus` class to allow submenu access on tablets.
99	 */
100	(function (container) {
101		var touchStartFn, i,
102			parentLink = container.querySelectorAll('.menu-item-has-children > a, .page_item_has_children > a');
103
104		if ('ontouchstart' in window) {
105			touchStartFn = function (e) {
106				var menuItem = this.parentNode,
107					i;
108
109				if (!menuItem.classList.contains('focus')) {
110					e.preventDefault();
111					for (i = 0; i < menuItem.parentNode.children.length; ++i) {
112						if (menuItem === menuItem.parentNode.children[i]) {
113							continue;
114						}
115						menuItem.parentNode.children[i].classList.remove('focus');
116					}
117					menuItem.classList.add('focus');
118				} else {
119					menuItem.classList.remove('focus');
120				}
121			};
122
123			for (i = 0; i < parentLink.length; ++i) {
124				parentLink[i].addEventListener('touchstart', touchStartFn, false);
125			}
126		}
127	}(container));
128});

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.