PageSourceSearch

https://mysalon.ie/wp-content/themes/mysalon/js/navigation.js?ver=20151215

js mysalon.ie collected 2026-10-08 19:58:04 UTC 3,204 bytes, 112 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	var container, button, menu, links, i, len;
9
10	container = document.getElementById( 'site-navigation' );
11	if ( ! container ) {
12		return;
13	}
14
15	button = container.getElementsByTagName( 'button' )[0];
16	if ( 'undefined' === typeof button ) {
17		return;
18	}
19
20	menuContainer = container.getElementsByTagName( 'div' )[0];
21
22	menu = container.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	menu.setAttribute( 'aria-expanded', 'false' );
31	menuContainer.setAttribute( 'aria-expanded', 'false' );
32
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			menuContainer.setAttribute( 'aria-expanded', 'false' );
43		} else {
44			container.className += ' toggled';
45			button.setAttribute( 'aria-expanded', 'true' );
46			menu.setAttribute( 'aria-expanded', 'true' );
47			menuContainer.setAttribute( 'aria-expanded', 'true' );
48		}
49	};
50
51	// Get all the link elements within the menu.
52	links    = menu.getElementsByTagName( 'a' );
53
54	// Each time a menu link is focused or blurred, toggle focus.
55	for ( i = 0, len = links.length; i < len; i++ ) {
56		links[i].addEventListener( 'focus', toggleFocus, true );
57		links[i].addEventListener( 'blur', toggleFocus, true );
58	}
59
60	/**
61	 * Sets or removes .focus class on an element.
62	 */
63	function toggleFocus() {
64		var self = this;
65
66		// Move up through the ancestors of the current link until we hit .nav-menu.
67		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
68
69			// On li elements toggle the class .focus.
70			if ( 'li' === self.tagName.toLowerCase() ) {
71				if ( -1 !== self.className.indexOf( 'focus' ) ) {
72					self.className = self.className.replace( ' focus', '' );
73				} else {
74					self.className += ' focus';
75				}
76			}
77
78			self = self.parentElement;
79		}
80	}
81
82	/**
83	 * Toggles `focus` class to allow submenu access on tablets.
84	 */
85	( function( container ) {
86		var touchStartFn, i,
87			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
88
89		if ( 'ontouchstart' in window ) {
90			touchStartFn = function( e ) {
91				var menuItem = this.parentNode, i;
92
93				if ( ! menuItem.classList.contains( 'focus' ) ) {
94					e.preventDefault();
95					for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
96						if ( menuItem === menuItem.parentNode.children[i] ) {
97							continue;
98						}
99						menuItem.parentNode.children[i].classList.remove( 'focus' );
100					}
101					menuItem.classList.add( 'focus' );
102				} else {
103					menuItem.classList.remove( 'focus' );
104				}
105			};
106
107			for ( i = 0; i < parentLink.length; ++i ) {
108				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
109			}
110		}
111	}( container ) );
112} )();

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.