PageSourceSearch

https://www.twik.io/wp-content/themes/twik_website_v2/js/navigation.js?ver=1.0.0

js twik.io collected 2026-09-25 02:40:51 UTC 3,113 bytes, 101 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
8
9( function() {
10	const siteNavigation = document.getElementById( 'site-navigation' );
11
12	// Return early if the navigation doesn't exist.
13	if ( ! siteNavigation ) {
14		return;
15	}
16
17	// const button = siteNavigation.getElementsByTagName( 'buttons' )[ 0 ];
18	// // Return early if the button doesn't exist.
19	// if ( 'undefined' === typeof button ) {
20	// 	return;
21	// }
22
23	const menu = siteNavigation.getElementsByTagName( 'ul' )[ 0 ];
24
25	// Hide menu toggle button if menu is empty and return early.
26	if ( 'undefined' === typeof menu ) {
27		// button.style.display = 'none';
28		document.getElementById('masthead').classList.add('hidden-menu');
29		return;
30	}
31
32	if ( ! menu.classList.contains( 'nav-menu' ) ) {
33		menu.classList.add( 'nav-menu' );
34	}
35
36	// Toggle the .toggled class and the aria-expanded value each time the button is clicked.
37	// button.addEventListener( 'click', function() {
38	// 	siteNavigation.classList.toggle( 'toggled' );
39
40	// 	if ( button.getAttribute( 'aria-expanded' ) === 'true' ) {
41	// 		button.setAttribute( 'aria-expanded', 'false' );
42	// 	} else {
43	// 		button.setAttribute( 'aria-expanded', 'true' );
44	// 	}
45	// } );
46
47	// Remove the .toggled class and set aria-expanded to false when the user clicks outside the navigation.
48	// document.addEventListener( 'click', function( event ) {
49	// 	const isClickInside = siteNavigation.contains( event.target );
50
51	// 	if ( ! isClickInside ) {
52	// 		siteNavigation.classList.remove( 'toggled' );
53	// 		button.setAttribute( 'aria-expanded', 'false' );
54	// 	}
55	// } );
56
57	// Get all the link elements within the menu.
58	const links = menu.getElementsByTagName( 'a' );
59
60	// Get all the link elements with children within the menu.
61	const linksWithChildren = menu.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
62
63	// Toggle focus each time a menu link is focused or blurred.
64	for ( const link of links ) {
65		link.addEventListener( 'focus', toggleFocus, true );
66		link.addEventListener( 'blur', toggleFocus, true );
67	}
68
69	// Toggle focus each time a menu link with children receive a touch event.
70	for ( const link of linksWithChildren ) {
71		link.addEventListener( 'touchstart', toggleFocus, false );
72	}
73
74	/**
75	 * Sets or removes .focus class on an element.
76	 */
77	function toggleFocus() {
78		if ( event.type === 'focus' || event.type === 'blur' ) {
79			let self = this;
80			// Move up through the ancestors of the current link until we hit .nav-menu.
81			while ( ! self.classList.contains( 'nav-menu' ) ) {
82				// On li elements toggle the class .focus.
83				if ( 'li' === self.tagName.toLowerCase() ) {
84					self.classList.toggle( 'focus' );
85				}
86				self = self.parentNode;
87			}
88		}
89
90		if ( event.type === 'touchstart' ) {
91			const menuItem = this.parentNode;
92			event.preventDefault();
93			for ( const link of menuItem.parentNode.children ) {
94				if ( menuItem !== link ) {
95					link.classList.remove( 'focus' );
96				}
97			}
98			menuItem.classList.toggle( 'focus' );
99		}
100	}
101}() );

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.