PageSourceSearch

https://www.gearbooker.com/blog/wp-content/themes/colormag.1.4.9/colormag/js/navigation.js?ver=7.1.2

js gearbooker.com collected 2026-09-24 11:56:31 UTC 3,190 bytes, 105 lines download raw bytes

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

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.