PageSourceSearch

https://policespiesoutoflives.org.uk/wp-content/themes/policespiesoutoflives/psool/js/navigation.js?ver=7.0.2

js policespiesoutoflives.org.uk collected 2026-10-02 06:34:25 UTC 3,662 bytes, 122 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	// hamburger button
15	button = container.getElementsByClassName( 'menu-toggle' )[0];
16	if ( 'undefined' === typeof button ) {
17		return;
18	}
19
20	menu = container.getElementsByTagName( 'ul' )[0];
21
22	// Hide menu toggle button if menu is empty and return early.
23	if ( 'undefined' === typeof menu ) {
24		button.style.display = 'none';
25		return;
26	}
27
28	menu.setAttribute( 'aria-expanded', 'false' );
29	if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
30		menu.className += ' nav-menu';
31	}
32
33	button.onclick = function() {
34		if ( -1 !== container.className.indexOf( 'main-small-navigation' ) ) {
35			container.className = container.className.replace( 'main-small-navigation', 'main-navigation' );
36			button.setAttribute( 'aria-expanded', 'false' );
37			menu.setAttribute( 'aria-expanded', 'false' );
38		} else {
39			container.className = container.className.replace( 'main-navigation', 'main-small-navigation' );
40			button.setAttribute( 'aria-expanded', 'true' );
41			menu.setAttribute( 'aria-expanded', 'true' );
42		}
43	};
44
45	// Get all the link elements within the menu.
46	links    = menu.getElementsByTagName( 'a' );
47
48	// Each time a menu link is focused or blurred, toggle focus.
49	for ( i = 0, len = links.length; i < len; i++ ) {
50		links[i].addEventListener( 'focus', toggleFocus, true );
51		links[i].addEventListener( 'blur', toggleFocus, true );
52	}
53
54	/**
55	 * Sets or removes .focus class on an element.
56	 */
57	function toggleFocus() {
58		var self = this;
59
60		// Move up through the ancestors of the current link until we hit .nav-menu.
61		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
62
63			// On li elements toggle the class .focus.
64			if ( 'li' === self.tagName.toLowerCase() ) {
65				if ( -1 !== self.className.indexOf( 'focus' ) ) {
66					self.className = self.className.replace( ' focus', '' );
67				} else {
68					self.className += ' focus';
69				}
70			}
71
72			self = self.parentElement;
73		}
74	}
75
76	/**
77	 * Toggles `focus` class to allow submenu access on tablets.
78	 */
79	( function( container ) {
80		var touchStartFn, i,
81			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
82
83		if ( 'ontouchstart' in window ) {
84			touchStartFn = function( e ) {
85				var menuItem = this.parentNode, i;
86
87				if ( ! menuItem.classList.contains( 'focus' ) ) {
88					e.preventDefault();
89					for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
90						if ( menuItem === menuItem.parentNode.children[i] ) {
91							continue;
92						}
93						menuItem.parentNode.children[i].classList.remove( 'focus' );
94					}
95					menuItem.classList.add( 'focus' );
96				} else {
97					menuItem.classList.remove( 'focus' );
98				}
99			};
100
101			for ( i = 0; i < parentLink.length; ++i ) {
102				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
103			}
104		}
105	}( container ) );
106
107} )();
108
109jQuery( document ).ready( function () {
110	/**
111	 * New responsive sub menu toggle
112	 */
113	// Add caret icon
114	jQuery( '.better-responsive-menu #site-navigation .menu-item-has-children' ).append( '<span class="sub-toggle"> <i class="icon-caret-down"></i> </span>' );
115
116	// Handle clicking on caret
117	jQuery( '.better-responsive-menu #site-navigation .sub-toggle' ).click( function () {
118		jQuery( this ).parent( '.menu-item-has-children' ).children( 'ul.sub-menu' ).first().slideToggle( '1000' );
119		jQuery( this ).children( '.icon-caret-down' ).first().toggleClass( 'icon-caret-up' );
120		jQuery( this ).toggleClass( 'active' );
121	} );
122} );

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.