PageSourceSearch

https://dgu.ac.in/blog/wp-content/themes/blogwaves/assets/js/navigation.js?ver=1.0.0

js dgu.ac.in collected 2026-10-07 20:03:32 UTC 3,441 bytes, 105 lines download raw bytes

1/**
2 * Theme functions file.
3 *
4 * Contains handlers for navigation and widget area.
5 */
6
7(function( $ ) {
8	var masthead, menuToggle, siteNavContain, siteNavigation;
9
10	function initMainNavigation( container ) {
11
12		// Add dropdown toggle that displays child menu items.
13		var dropdownToggle = $( '<button />', { 'class': 'dropdown-toggle', 'aria-expanded': false })
14			.append( $( '<span />', { 'class': 'screen-reader-text' }) );
15
16		container.find( '.menu-item-has-children > a, .page_item_has_children > a' ).after( dropdownToggle );
17
18		// Set the active submenu dropdown toggle button initial state.
19		container.find( '.current-menu-ancestor > button' )
20			.addClass( 'toggled-on' )
21			.attr( 'aria-expanded', 'true' )
22			.find( '.screen-reader-text' )
23		// Set the active submenu initial state.
24		container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
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			_this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
35
36		});
37	}
38
39	initMainNavigation( $( '.main-navigation' ) );
40
41	masthead       = $( '#masthead' );
42	menuToggle     = masthead.find( '.menu-toggle' );
43	siteNavContain = masthead.find( '.main-navigation' );
44	siteNavigation = masthead.find( '.main-navigation > div > ul' );
45
46	// Enable menuToggle.
47	(function() {
48
49		// Return early if menuToggle is missing.
50		if ( ! menuToggle.length ) {
51			return;
52		}
53
54		// Add an initial value for the attribute.
55		menuToggle.attr( 'aria-expanded', 'false' );
56
57		menuToggle.on( 'click.blogwaves', function() {
58			siteNavContain.toggleClass( 'toggled-on' );
59
60			$( this ).attr( 'aria-expanded', siteNavContain.hasClass( 'toggled-on' ) );
61		});
62	})();
63
64	// Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility.
65	(function() {
66		if ( ! siteNavigation.length || ! siteNavigation.children().length ) {
67			return;
68		}
69
70		// Toggle `focus` class to allow submenu access on tablets.
71		function toggleFocusClassTouchScreen() {
72			if ( 'none' === $( '.menu-toggle' ).css( 'display' ) ) {
73
74				$( document.body ).on( 'touchstart.blogwaves', function( e ) {
75					if ( ! $( e.target ).closest( '.main-navigation li' ).length ) {
76						$( '.main-navigation li' ).removeClass( 'focus' );
77					}
78				});
79
80				siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' )
81					.on( 'touchstart.blogwaves', function( e ) {
82						var el = $( this ).parent( 'li' );
83
84						if ( ! el.hasClass( 'focus' ) ) {
85							e.preventDefault();
86							el.toggleClass( 'focus' );
87							el.siblings( '.focus' ).removeClass( 'focus' );
88						}
89					});
90
91			} else {
92				siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' ).unbind( 'touchstart.blogwaves' );
93			}
94		}
95
96		if ( 'ontouchstart' in window ) {
97			$( window ).on( 'resize.blogwaves', toggleFocusClassTouchScreen );
98			toggleFocusClassTouchScreen();
99		}
100
101		siteNavigation.find( 'a' ).on( 'focus.blogwaves blur.blogwaves', function() {
102			$( this ).parents( '.menu-item, .page_item' ).toggleClass( 'focus' );
103		});
104	})();
105})( 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.