PageSourceSearch

https://sudoroom.org/wp-content/themes/auberge/assets/js/scripts-navigation.js?ver=3.0.2

js sudoroom.org collected 2026-09-24 18:36:43 UTC 4,176 bytes, 231 lines download raw bytes

1/**
2 * Accessible navigation
3 *
4 * @link  http://a11yproject.com/
5 * @link  https://codeable.io/community/wordpress-accessibility-creating-accessible-dropdown-menus/
6 *
7 * @package    Auberge
8 * @copyright  WebMan Design, Oliver Juhas
9 *
10 * @since    1.4.8
11 * @version  2.9.0
12 */
13
14( function( $ ) {
15
16	'use strict';
17
18
19
20
21
22	/**
23	 * Variables
24	 */
25
26		var
27			$aubergeSiteNavigation   = $( document.getElementById( 'site-navigation' ) ),
28			$aubergeSiteMenuPrimary  = $( document.getElementById( 'menu-primary' ) ),
29			$aubergeMenuToggleButton = $( document.getElementById( 'menu-toggle' ) );
30
31
32
33	/**
34	 * Setting `.focus` class for menu parent
35	 */
36
37		$aubergeSiteNavigation
38			.on( 'focus.aria mouseenter.aria', '.menu-item-has-children', function ( e ) {
39
40				// Processing
41
42					$( e.currentTarget )
43						.addClass( 'focus' );
44
45			} );
46
47		$aubergeSiteNavigation
48			.on( 'blur.aria mouseleave.aria', '.menu-item-has-children', function ( e ) {
49
50				// Processing
51
52					$( e.currentTarget )
53						.removeClass( 'focus' );
54
55			} );
56
57
58
59	/**
60	 * Touch-enabled
61	 */
62
63		$aubergeSiteNavigation
64			.on( 'touchstart', '.menu-item-has-children > a', function( e ) {
65
66				// Variables
67
68					var
69						el = $( this ).parent( 'li' );
70
71
72				// Processing
73
74					/**
75					 * First touch does not trigger the link, only opens the submenu.
76					 * Second touch does trigger the link.
77					 */
78					if ( ! el.hasClass( 'focus' ) ) {
79						e.preventDefault();
80
81						el
82							.toggleClass( 'focus' )
83							.siblings( '.focus' )
84								.removeClass( 'focus' );
85					}
86
87			} );
88
89
90
91	/**
92	 * Mobile navigation
93	 */
94
95		/**
96		 * Mobile menu actions
97		 */
98		function aubergeMobileMenuActions() {
99
100			// Processing
101
102				if ( ! $aubergeSiteNavigation.hasClass( 'active' ) ) {
103
104					$aubergeSiteMenuPrimary
105						.attr( 'aria-hidden', 'true' );
106
107					$aubergeMenuToggleButton
108						.attr( 'aria-expanded', 'false' );
109
110				}
111
112				$aubergeSiteNavigation
113					.on( 'keydown', function( e ) {
114
115						// Processing
116
117							if ( e.which === 27 ) {
118
119								// ESC key
120
121									e.preventDefault();
122
123									$aubergeSiteNavigation
124										.removeClass( 'active' );
125
126									$aubergeSiteMenuPrimary
127										.attr( 'aria-hidden', 'true' );
128
129									$aubergeMenuToggleButton
130										.focus();
131
132							}
133
134					} );
135
136		} // /aubergeMobileMenuActions
137
138		// Default mobile menu setup
139
140			if ( 880 >= window.innerWidth ) {
141
142				$aubergeSiteNavigation
143					.removeClass( 'active' );
144
145				aubergeMobileMenuActions();
146
147			}
148
149		// Clicking the menu toggle button
150
151			$aubergeMenuToggleButton
152				.on( 'click', function( e ) {
153
154					// Processing
155
156						e.preventDefault();
157
158						$aubergeSiteNavigation
159							.toggleClass( 'active' );
160
161						if ( $aubergeSiteNavigation.hasClass( 'active' ) ) {
162
163							$aubergeSiteMenuPrimary
164								.attr( 'aria-hidden', 'false' );
165
166							$aubergeMenuToggleButton
167								.attr( 'aria-expanded', 'true' );
168
169							$( 'html, body' )
170								.stop()
171								.animate( { scrollTop : '0px' }, 0 );
172
173						} else {
174
175							$aubergeSiteMenuPrimary
176								.attr( 'aria-hidden', 'true' );
177
178							$aubergeMenuToggleButton
179								.attr( 'aria-expanded', 'false' );
180
181						}
182
183				} );
184
185		// Refocus to menu toggle button once the end of the menu is reached
186
187			$aubergeSiteNavigation
188				.on( 'focus.aria', '.menu-toggle-skip-link', function( e ) {
189
190					// Processing
191
192						$aubergeMenuToggleButton
193							.focus();
194
195				} );
196
197		// Disable mobile navigation on wider screens
198
199			$( window )
200				.on( 'resize orientationchange', function( e ) {
201
202					// Processing
203
204						if ( 880 < window.innerWidth ) {
205
206							// On desktops
207
208							$aubergeSiteNavigation
209								.removeClass( 'active' );
210
211							$aubergeSiteMenuPrimary
212								.attr( 'aria-hidden', 'false' );
213
214							$aubergeMenuToggleButton
215								.attr( 'aria-expanded', 'true' );
216
217						} else {
218
219							// On mobiles
220
221							aubergeMobileMenuActions();
222
223						}
224
225				} );
226
227
228
229
230
231} )( jQuery );

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.