PageSourceSearch

https://futbolistasla.org/wp-content/themes/shoreditch/js/navigation.js?ver=20151231

js futbolistasla.org collected 2026-10-02 01:06:50 UTC 5,150 bytes, 159 lines download raw bytes

1/* global shoreditchScreenReaderText */
2( function( $ ) {
3
4	var body, masthead, menuToggle, siteMenu, siteNavigation;
5
6	function initMainNavigation( container ) {
7
8		// Add dropdown toggle that displays child menu items.
9		var dropdownToggle = $( '<button />', {
10			'class': 'dropdown-toggle',
11			'aria-expanded': false
12		} ).append( $( '<span />', {
13			'class': 'screen-reader-text',
14			text: shoreditchScreenReaderText.expand
15		} ) );
16
17		container.find( '.menu-item-has-children > a' ).after( dropdownToggle );
18
19		// Toggle buttons and submenu items with active children menu items.
20		container.find( '.current-menu-ancestor > button' ).addClass( 'toggled-on' );
21		container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
22
23		// Add menu items with submenus to aria-haspopup="true".
24		container.find( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' );
25
26		container.find( '.dropdown-toggle' ).click( function( e ) {
27			var _this            = $( this ),
28				screenReaderSpan = _this.find( '.screen-reader-text' );
29
30			e.preventDefault();
31			_this.toggleClass( 'toggled-on' );
32			_this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
33
34			// jscs:disable
35			_this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
36			// jscs:enable
37			screenReaderSpan.text( screenReaderSpan.text() === shoreditchScreenReaderText.expand ? shoreditchScreenReaderText.collapse : shoreditchScreenReaderText.expand );
38		} );
39
40		//Ensure submenus do not fall outside the left side of the window, rendering them unusable.
41		var submenus = container.find( '.children, .sub-menu' );
42
43		//Return early if no submenus exist
44		if ( ! submenus.length ) {
45			return;
46		} else {
47			submenus.each( function() {
48				var parent = $( this ).parent( 'li' );
49
50				parent.hover(
51					function() {
52						var submenu = $( this ).find( '> .sub-menu, > .children' );
53
54						if ( $( submenu ) ) {
55							if ( $( submenu ).offset().left < 0 ) {
56								$( submenu ).addClass( 'offscreen' );
57							}
58						}
59					},
60					function() {
61						$( this ).find( '> .sub-menu, > .children' ).removeClass( 'offscreen' );
62					}
63				);
64			} );
65		}
66	}
67	initMainNavigation( $( '.main-navigation' ) );
68
69	masthead         = $( '#masthead' );
70	menuToggle       = masthead.find( '#menu-toggle' );
71	siteMenu         = masthead.find( '#site-menu' );
72	siteNavigation   = masthead.find( '#site-navigation' );
73
74	// Enable menuToggle.
75	( function() {
76
77		// Return early if menuToggle is missing.
78		if ( ! menuToggle.length ) {
79			return;
80		}
81
82		// Add an initial values for the attribute.
83		menuToggle.add( siteNavigation ).attr( 'aria-expanded', 'false' );
84
85		menuToggle.on( 'click.shoreditch', function() {
86			$( this ).add( siteMenu ).add( siteNavigation ).toggleClass( 'toggled-on' );
87
88			// jscs:disable
89			$( this ).add( siteMenu ).add( siteNavigation ).attr( 'aria-expanded', $( this ).add( siteNavigation ).attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
90			// jscs:enable
91		} );
92	} )();
93
94	// Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility.
95	( function() {
96		if ( ! siteNavigation.length || ! siteNavigation.children().length ) {
97			return;
98		}
99
100		// Toggle `focus` class to allow submenu access on tablets.
101		function toggleFocusClassTouchScreen() {
102			if ( window.innerWidth >= 896 ) {
103				$( document.body ).on( 'touchstart.shoreditch', function( e ) {
104					if ( ! $( e.target ).closest( '.main-navigation li' ).length ) {
105						$( '.main-navigation li' ).removeClass( 'focus' );
106					}
107				} );
108				siteNavigation.find( '.menu-item-has-children > a' ).on( 'touchstart.shoreditch', function( e ) {
109					var el = $( this ).parent( 'li' );
110
111					if ( ! el.hasClass( 'focus' ) ) {
112						e.preventDefault();
113						el.toggleClass( 'focus' );
114						el.siblings( '.focus' ).removeClass( 'focus' );
115					}
116				} );
117			} else {
118				siteNavigation.find( '.menu-item-has-children > a' ).unbind( 'touchstart.shoreditch' );
119			}
120		}
121
122		if ( 'ontouchstart' in window ) {
123			$( window ).on( 'resize.shoreditch', toggleFocusClassTouchScreen );
124			toggleFocusClassTouchScreen();
125		}
126
127		siteNavigation.find( 'a' ).on( 'focus.shoreditch blur.shoreditch', function() {
128			$( this ).parents( '.menu-item' ).toggleClass( 'focus' );
129		} );
130	} )();
131
132	// Add the default ARIA attributes for the menu toggle and the navigations.
133	function onResizeARIA() {
134		if ( window.innerWidth < 896 ) {
135			if ( menuToggle.hasClass( 'toggled-on' ) ) {
136				menuToggle.attr( 'aria-expanded', 'true' );
137				siteMenu.attr( 'aria-expanded', 'true' );
138				siteNavigation.attr( 'aria-expanded', 'true' );
139			} else {
140				menuToggle.attr( 'aria-expanded', 'false' );
141				siteMenu.attr( 'aria-expanded', 'false' );
142				siteNavigation.attr( 'aria-expanded', 'false' );
143			}
144		} else {
145			menuToggle.removeAttr( 'aria-expanded' );
146			siteMenu.removeAttr( 'aria-expanded' );
147			siteNavigation.removeAttr( 'aria-expanded' );
148		}
149	}
150
151	$( document ).ready( function() {
152		body = $( document.body );
153
154		$( window )
155			.on( 'load.shoreditch', onResizeARIA )
156			.on( 'resize.shoreditch', onResizeARIA );
157	} );
158
159} )( 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.