PageSourceSearch

https://velomania.ru/wp-content/themes/hitmag/js/navigation.js?ver=1.4.4

js velomania.ru collected 2026-09-24 21:55:49 UTC 2,807 bytes, 109 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
8// polyfill forEach
9// https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill
10if ( window.NodeList && ! NodeList.prototype.forEach ) {
11	NodeList.prototype.forEach = function( callback, thisArg ) {
12		var i;
13		var len = this.length;
14
15		thisArg = thisArg || window;
16
17		for ( i = 0; i < len; i++ ) {
18			callback.call( thisArg, this[ i ], i, this );
19		}
20	};
21}
22
23( function() {
24
25	const navigationIds = ['site-navigation', 'top-navigation'];
26
27	navigationIds.forEach(initNavigation);
28
29	function initNavigation(navigationId) {
30
31		const siteNavigation = document.getElementById(navigationId);
32
33		// Return early if the navigation doesn't exist.
34		if ( ! siteNavigation ) {
35			return;
36		}
37	
38		const menu = siteNavigation.getElementsByTagName( 'ul' )[ 0 ];
39	
40		// If menu is empty return early.
41		if ( 'undefined' === typeof menu ) {
42			return;
43		}
44	
45		if ( ! menu.classList.contains( 'nav-menu' ) ) {
46			menu.classList.add( 'nav-menu' );
47		}
48	
49		// Get all the link elements within the menu.
50		const links = menu.getElementsByTagName( 'a' );
51	
52		// Toggle focus each time a menu link is focused or blurred.
53		for ( const link of links ) {
54			link.addEventListener( 'focus', toggleFocus, true );
55			link.addEventListener( 'blur', toggleFocus, true );
56		}
57	
58		/**
59		 * Sets or removes .focus class on an element.
60		 */
61		function toggleFocus(event) {
62			if ( event.type === 'focus' || event.type === 'blur' ) {
63				let self = this;
64				// Move up through the ancestors of the current link until we hit .nav-menu.
65				while ( ! self.classList.contains( 'nav-menu' ) ) {
66					// On li elements toggle the class .focus.
67					if ( 'li' === self.tagName.toLowerCase() ) {
68						self.classList.toggle( 'focus' );
69					}
70					self = self.parentNode;
71				}
72			}
73		}
74	}
75}() );
76
77jQuery(document).ready(function(){
78
79	var mobMainNav = jQuery('.responsive-mainnav'),
80		mainNavUl = mobMainNav.find('ul#primary-menu'),
81		mNavWrapper = jQuery('<div class="hm-nwrap"></div>');
82
83	mNavWrapper.appendTo(mobMainNav);
84	jQuery('#site-navigation ul:first-child').clone().appendTo(mNavWrapper);
85
86	jQuery('#main-nav-button').on( "click", function(event){
87		event.preventDefault();
88		mobMainNav.slideToggle(0);
89		mainNavUl.show();
90	});
91	
92});
93
94jQuery(document).ready(function(){
95
96	var mobTopNav = jQuery('.responsive-topnav'),
97	topNavUl = mobTopNav.find('ul#top-menu'),
98	tNavWrapper = jQuery('<div class="hm-nwrap"></div>');
99
100	tNavWrapper.appendTo(mobTopNav);
101	jQuery('#top-navigation ul:first-child').clone().appendTo(tNavWrapper);
102
103	jQuery('#top-nav-button').on( "click", function(event){
104		event.preventDefault();
105		mobTopNav.slideToggle(0);
106		topNavUl.show();
107	});
108	
109});

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.