PageSourceSearch

https://sadio.pro/wp-content/themes/bosa/assets/js/navigation.js?ver=0.8

js sadio.pro collected 2026-10-02 02:05:58 UTC 6,059 bytes, 214 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 *primary navigation.
10*/
11( function() {
12	var container, button, menu, links, i, len;
13
14	container = document.getElementById( 'site-navigation' );
15	if ( ! container ) {
16		return;
17	}
18
19	button = container.getElementsByTagName( 'button' )[0];
20	if ( 'undefined' === typeof button ) {
21		return;
22	}
23
24	menu = container.getElementsByTagName( 'ul' )[0];
25
26	// Hide menu toggle button if menu is empty and return early.
27	if ( 'undefined' === typeof menu ) {
28		button.style.display = 'none';
29		return;
30	}
31
32	menu.setAttribute( 'aria-expanded', 'false' );
33	if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
34		menu.className += ' nav-menu';
35	}
36
37	button.onclick = function() {
38		if ( -1 !== container.className.indexOf( 'toggled' ) ) {
39			container.className = container.className.replace( ' toggled', '' );
40			button.setAttribute( 'aria-expanded', 'false' );
41			menu.setAttribute( 'aria-expanded', 'false' );
42		} else {
43			container.className += ' toggled';
44			button.setAttribute( 'aria-expanded', 'true' );
45			menu.setAttribute( 'aria-expanded', 'true' );
46		}
47	};
48
49	// Get all the link elements within the menu.
50	links    = menu.getElementsByTagName( 'a' );
51
52	// Each time a menu link is focused or blurred, toggle focus.
53	for ( i = 0, len = links.length; i < len; i++ ) {
54		links[i].addEventListener( 'focus', toggleFocus, true );
55		links[i].addEventListener( 'blur', toggleFocus, true );
56	}
57
58	/**
59	 * Sets or removes .focus class on an element.
60	 */
61	function toggleFocus() {
62		var self = this;
63
64		// Move up through the ancestors of the current link until we hit .nav-menu.
65		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
66
67			// On li elements toggle the class .focus.
68			if ( 'li' === self.tagName.toLowerCase() ) {
69				if ( -1 !== self.className.indexOf( 'focus' ) ) {
70					self.className = self.className.replace( ' focus', '' );
71				} else {
72					self.className += ' focus';
73				}
74			}
75
76			self = self.parentElement;
77		}
78	}
79
80	/**
81	 * Toggles `focus` class to allow submenu access on tablets.
82	 */
83	( function( container ) {
84		var touchStartFn, i,
85			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
86
87		if ( 'ontouchstart' in window ) {
88			touchStartFn = function( e ) {
89				var menuItem = this.parentNode, i;
90
91				if ( ! menuItem.classList.contains( 'focus' ) ) {
92					e.preventDefault();
93					for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
94						if ( menuItem === menuItem.parentNode.children[i] ) {
95							continue;
96						}
97						menuItem.parentNode.children[i].classList.remove( 'focus' );
98					}
99					menuItem.classList.add( 'focus' );
100				} else {
101					menuItem.classList.remove( 'focus' );
102				}
103			};
104
105			for ( i = 0; i < parentLink.length; ++i ) {
106				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
107			}
108		}
109	}( container ) );
110} )();
111
112/**
113 *secondary navigation.
114*/
115( function() {
116	var container, button, menu, links, i, len;
117
118	container = document.getElementById( 'secondary-navigation' );
119	if ( ! container ) {
120		return;
121	}
122
123	button = container.getElementsByTagName( 'button' )[0];
124	if ( 'undefined' === typeof button ) {
125		return;
126	}
127
128	menu = container.getElementsByTagName( 'ul' )[0];
129
130	// Hide menu toggle button if menu is empty and return early.
131	if ( 'undefined' === typeof menu ) {
132		button.style.display = 'none';
133		return;
134	}
135
136	menu.setAttribute( 'aria-expanded', 'false' );
137	if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
138		menu.className += ' nav-menu';
139	}
140
141	button.onclick = function() {
142		if ( -1 !== container.className.indexOf( 'toggled' ) ) {
143			container.className = container.className.replace( ' toggled', '' );
144			button.setAttribute( 'aria-expanded', 'false' );
145			menu.setAttribute( 'aria-expanded', 'false' );
146		} else {
147			container.className += ' toggled';
148			button.setAttribute( 'aria-expanded', 'true' );
149			menu.setAttribute( 'aria-expanded', 'true' );
150		}
151	};
152
153	// Get all the link elements within the menu.
154	links    = menu.getElementsByTagName( 'a' );
155
156	// Each time a menu link is focused or blurred, toggle focus.
157	for ( i = 0, len = links.length; i < len; i++ ) {
158		links[i].addEventListener( 'focus', toggleFocus, true );
159		links[i].addEventListener( 'blur', toggleFocus, true );
160	}
161
162	/**
163	 * Sets or removes .focus class on an element.
164	 */
165	function toggleFocus() {
166		var self = this;
167
168		// Move up through the ancestors of the current link until we hit .nav-menu.
169		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
170
171			// On li elements toggle the class .focus.
172			if ( 'li' === self.tagName.toLowerCase() ) {
173				if ( -1 !== self.className.indexOf( 'focus' ) ) {
174					self.className = self.className.replace( ' focus', '' );
175				} else {
176					self.className += ' focus';
177				}
178			}
179
180			self = self.parentElement;
181		}
182	}
183
184	/**
185	 * Toggles `focus` class to allow submenu access on tablets.
186	 */
187	( function( container ) {
188		var touchStartFn, i,
189			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
190
191		if ( 'ontouchstart' in window ) {
192			touchStartFn = function( e ) {
193				var menuItem = this.parentNode, i;
194
195				if ( ! menuItem.classList.contains( 'focus' ) ) {
196					e.preventDefault();
197					for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
198						if ( menuItem === menuItem.parentNode.children[i] ) {
199							continue;
200						}
201						menuItem.parentNode.children[i].classList.remove( 'focus' );
202					}
203					menuItem.classList.add( 'focus' );
204				} else {
205					menuItem.classList.remove( 'focus' );
206				}
207			};
208
209			for ( i = 0; i < parentLink.length; ++i ) {
210				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
211			}
212		}
213	}( container ) );
214} )();

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.