PageSourceSearch

https://skin.place/blog/wp-content/themes/place/js/navigation.js?ver=1.0.0

js skin.place collected 2026-10-01 16:20:00 UTC 7,255 bytes, 282 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	const siteNavigation = document.getElementById( 'site-navigation' );
9
10	// Return early if the navigation doesn't exist.
11	if ( ! siteNavigation ) {
12		return;
13	}
14
15	const button = siteNavigation.getElementsByTagName( 'button' )[ 0 ];
16
17	// Return early if the button doesn't exist.
18	if ( 'undefined' === typeof button ) {
19		return;
20	}
21
22	const menu = siteNavigation.getElementsByTagName( 'ul' )[ 0 ];
23
24	// Hide menu toggle button if menu is empty and return early.
25	if ( 'undefined' === typeof menu ) {
26		button.style.display = 'none';
27		return;
28	}
29
30	if ( ! menu.classList.contains( 'nav-menu' ) ) {
31		menu.classList.add( 'nav-menu' );
32	}
33
34	// Toggle the .toggled class and the aria-expanded value each time the button is clicked.
35	button.addEventListener( 'click', function() {
36		siteNavigation.classList.toggle( 'toggled' );
37
38		if ( button.getAttribute( 'aria-expanded' ) === 'true' ) {
39			button.setAttribute( 'aria-expanded', 'false' );
40		} else {
41			button.setAttribute( 'aria-expanded', 'true' );
42		}
43	} );
44
45	// Remove the .toggled class and set aria-expanded to false when the user clicks outside the navigation.
46	document.addEventListener( 'click', function( event ) {
47		const isClickInside = siteNavigation.contains( event.target );
48
49		if ( ! isClickInside ) {
50			siteNavigation.classList.remove( 'toggled' );
51			button.setAttribute( 'aria-expanded', 'false' );
52		}
53	} );
54
55	// Get all the link elements within the menu.
56	const links = menu.getElementsByTagName( 'a' );
57
58	// Get all the link elements with children within the menu.
59	const linksWithChildren = menu.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
60
61	// Toggle focus each time a menu link is focused or blurred.
62	for ( const link of links ) {
63		link.addEventListener( 'focus', toggleFocus, true );
64		link.addEventListener( 'blur', toggleFocus, true );
65	}
66
67	// Toggle focus each time a menu link with children receive a touch event.
68	for ( const link of linksWithChildren ) {
69		link.addEventListener( 'touchstart', toggleFocus, false );
70	}
71
72	/**
73	 * Sets or removes .focus class on an element.
74	 */
75	function toggleFocus() {
76		if ( event.type === 'focus' || event.type === 'blur' ) {
77			let self = this;
78			// Move up through the ancestors of the current link until we hit .nav-menu.
79			while ( ! self.classList.contains( 'nav-menu' ) ) {
80				// On li elements toggle the class .focus.
81				if ( 'li' === self.tagName.toLowerCase() ) {
82					self.classList.toggle( 'focus' );
83				}
84				self = self.parentNode;
85			}
86		}
87
88		if ( event.type === 'touchstart' ) {
89			const menuItem = this.parentNode;
90			event.preventDefault();
91			for ( const link of menuItem.parentNode.children ) {
92				if ( menuItem !== link ) {
93					link.classList.remove( 'focus' );
94				}
95			}
96			menuItem.classList.toggle( 'focus' );
97		}
98	}
99}() );
100
101( function() {
102	function initFooterAccordion() {
103		const toggles = document.querySelectorAll( '.footer-accordion__toggle' );
104
105		if ( ! toggles.length ) {
106			return;
107		}
108
109		const breakpoint = window.matchMedia( '(max-width: 990px)' );
110
111		const getContent = ( toggle ) => {
112			const targetId = toggle.getAttribute( 'data-accordion-target' );
113
114			if ( ! targetId ) {
115				return null;
116			}
117
118			return document.getElementById( targetId );
119		};
120
121		const openContent = ( toggle, content, animate ) => {
122			toggle.setAttribute( 'aria-expanded', 'true' );
123			content.removeAttribute( 'hidden' );
124			content.style.display = 'flex';
125			content.style.flexDirection = 'column';
126
127			if ( ! breakpoint.matches ) {
128				content.style.maxHeight = '';
129				return;
130			}
131
132			if ( ! animate ) {
133				content.style.maxHeight = 'none';
134				return;
135			}
136
137			content.style.maxHeight = '0px';
138			// Force reflow so transition runs.
139			// eslint-disable-next-line no-unused-expressions
140			content.offsetHeight;
141			content.style.maxHeight = content.scrollHeight + 'px';
142
143			const handleTransitionEnd = ( event ) => {
144				if ( event.propertyName !== 'max-height' ) {
145					return;
146				}
147
148				content.style.maxHeight = 'none';
149				content.removeEventListener( 'transitionend', handleTransitionEnd );
150			};
151
152			content.addEventListener( 'transitionend', handleTransitionEnd );
153		};
154
155		const closeContent = ( toggle, content, animate ) => {
156			toggle.setAttribute( 'aria-expanded', 'false' );
157
158			const finalizeClose = () => {
159				content.setAttribute( 'hidden', '' );
160				content.style.display = 'none';
161				content.style.maxHeight = '0px';
162			};
163
164			if ( ! breakpoint.matches ) {
165				finalizeClose();
166				return;
167			}
168
169			if ( ! animate ) {
170				finalizeClose();
171				return;
172			}
173
174			const startHeight = content.scrollHeight;
175
176			if ( ! startHeight ) {
177				finalizeClose();
178				return;
179			}
180
181			content.style.maxHeight = startHeight + 'px';
182			// Force reflow.
183			// eslint-disable-next-line no-unused-expressions
184			content.offsetHeight;
185			content.style.maxHeight = '0px';
186
187			const handleTransitionEnd = ( event ) => {
188				if ( event.propertyName !== 'max-height' ) {
189					return;
190				}
191
192				content.removeEventListener( 'transitionend', handleTransitionEnd );
193				finalizeClose();
194			};
195
196			content.addEventListener( 'transitionend', handleTransitionEnd );
197		};
198
199		const applyDesktopState = () => {
200			toggles.forEach( ( toggle ) => {
201				const content = getContent( toggle );
202
203				if ( ! content ) {
204					return;
205				}
206
207				toggle.classList.remove( 'footer-accordion__toggle--open' );
208				toggle.setAttribute( 'aria-expanded', 'true' );
209				content.removeAttribute( 'hidden' );
210				content.style.display = '';
211				content.style.maxHeight = '';
212			} );
213		};
214
215		const applyMobileState = () => {
216			toggles.forEach( ( toggle ) => {
217				const content = getContent( toggle );
218
219				if ( ! content ) {
220					return;
221				}
222
223				const shouldOpen = toggle.classList.contains( 'footer-accordion__toggle--open' );
224
225				if ( shouldOpen ) {
226					openContent( toggle, content, false );
227				} else {
228					closeContent( toggle, content, false );
229				}
230			} );
231		};
232
233		const handleBreakpointChange = ( media ) => {
234			if ( media.matches ) {
235				applyMobileState();
236			} else {
237				applyDesktopState();
238			}
239		};
240
241		const handleToggleClick = ( event ) => {
242			const toggle = event.currentTarget;
243
244			if ( ! breakpoint.matches ) {
245				return;
246			}
247
248			const willOpen = ! toggle.classList.contains( 'footer-accordion__toggle--open' );
249			toggle.classList.toggle( 'footer-accordion__toggle--open', willOpen );
250
251			const content = getContent( toggle );
252
253			if ( ! content ) {
254				return;
255			}
256
257			if ( willOpen ) {
258				openContent( toggle, content, true );
259			} else {
260				closeContent( toggle, content, true );
261			}
262		};
263
264		toggles.forEach( ( toggle ) => {
265			toggle.addEventListener( 'click', handleToggleClick );
266		} );
267
268		handleBreakpointChange( breakpoint );
269
270		if ( typeof breakpoint.addEventListener === 'function' ) {
271			breakpoint.addEventListener( 'change', handleBreakpointChange );
272		} else {
273			breakpoint.addListener( handleBreakpointChange );
274		}
275	}
276
277	if ( document.readyState === 'loading' ) {
278		document.addEventListener( 'DOMContentLoaded', initFooterAccordion );
279	} else {
280		initFooterAccordion();
281	}
282}() );

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.