PageSourceSearch

http://www.csshl.ca/wp-content/themes/jaws/js/navigation-mobile.js?ver=12052023x5

js csshl.ca collected 2026-10-02 13:33:26 UTC 7,751 bytes, 256 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 body,
9		mobileContainer,
10		mobileNavContainer,
11		mobileButtonTop,
12		mobileMenuContainer,
13		buttonClick,
14		mobileMenu,
15		mobileLinks,
16		i,
17		len;
18
19	body = document.getElementsByTagName( 'body' )[0];
20
21	mobileContainer = document.getElementById( 'site-navigation-mobile' );
22	if ( ! mobileContainer ) {
23		return;
24	}
25
26	mobileNavContainer = mobileContainer.getElementsByTagName( 'section' )[0];
27
28	mobileButtonTop = document.getElementById( 'mobile-menu-button-top' );
29	if ( ! mobileButtonTop ) {
30		return;
31	}
32
33	var menuContainerMobile = $( '#primary-menu-mobile' );
34
35	// mobileMenuContainer = mobileContainer.getElementsByClassName('menu-main-menu-container-top')[0];
36	// if( ! mobileMenuContainer) {
37	// 	mobileMenuContainer = mobileContainer.getElementsByClassName('menu-main-menu-container')[0];
38	// }
39
40	buttonClick = mobileContainer.getElementsByTagName( 'button' )[0];
41	if ( 'undefined' === typeof buttonClick ) {
42		return;
43	}
44
45	mobileMenu = mobileContainer.getElementsByTagName( 'ul' )[0];
46
47	// Hide menu toggle button if menu is empty and return early.
48	if ( 'undefined' === typeof mobileMenu ) {
49		buttonClick.style.display = 'none';
50		return;
51	}
52
53	mobileMenu.setAttribute( 'aria-expanded', 'false' );
54	if ( -1 === mobileMenu.className.indexOf( 'nav-menu' ) ) {
55		mobileMenu.className += ' nav-menu';
56	}
57
58	buttonClick.onclick = function() {
59		if ( -1 !== mobileContainer.className.indexOf( 'toggled' ) ) {
60			body.className = body.className.replace(' mobile-menu-opened','');
61			mobileContainer.className = mobileContainer.className.replace( ' toggled', '' );
62			mobileNavContainer.className = mobileNavContainer.className.replace( ' show-mobile-menu', '' );
63			mobileButtonTop.className = mobileButtonTop.className.replace( 'toggled', '' );
64			// if(typeof mobileMenuContainer != 'undefined') {
65			// 	mobileMenuContainer.className = mobileMenuContainer.className.replace( ' toggled', '' );
66			// }
67
68			menuContainerMobile.parent()[0].className = menuContainerMobile.parent()[0].className.replace( ' toggled', '' );
69
70			buttonClick.className = buttonClick.className.replace( ' toggled', '' );
71			buttonClick.setAttribute( 'aria-expanded', 'false' );
72			mobileMenu.setAttribute( 'aria-expanded', 'false' );
73		} else {
74			close_sub_uls();
75			body.className += ' mobile-menu-opened';
76			mobileContainer.className += ' toggled';
77			mobileNavContainer.className += ' show-mobile-menu';
78			mobileButtonTop.className += 'toggled';
79			// if(typeof mobileMenuContainer != 'undefined') {
80			// 	mobileMenuContainer.className += ' toggled';
81			// }
82
83			menuContainerMobile.parent()[0].className += ' toggled';
84
85			buttonClick.className += ' toggled';
86			buttonClick.setAttribute( 'aria-expanded', 'true' );
87			mobileMenu.setAttribute( 'aria-expanded', 'true' );
88		}
89	};
90
91	// Get all the link elements within the menu.
92	mobileLinks = mobileMenu.getElementsByTagName( 'a' );
93
94	//Each time a menu link is focused or blurred, toggle focus.
95	for ( i = 0, len = mobileLinks.length; i < len; i++ ) {
96		mobileLinks[i].addEventListener( 'focus', toggleFocus, true );
97		mobileLinks[i].addEventListener( 'blur', toggleFocus, true );
98	}
99
100	//add expand collapse to mobile menu
101
102	menuContainerMobile.find('ul').each(function() {
103		var sub_ul = $(this),
104			parent_a = sub_ul.prev('a');
105
106		var expand = parent_a.before('<span class="mobileExpand"></span> ').find('.mobileExpand');
107	});
108
109	//expand / collapse action (SUBLEVELS)
110	$('.mobileExpand').on('click',function() {
111
112		//expand current sub level
113		var sub = $(this),
114		child_ul = sub.parent('li').find('ul').first();
115
116		if ( -1 !== sub[0].className.indexOf( 'expanded' ) ) {
117			sub[0].className = sub[0].className.replace( ' expanded', '' );
118			child_ul[0].className = child_ul[0].className.replace( ' opened', '' );
119		} else {
120			sub[0].className += ' expanded';
121			child_ul[0].className += ' opened';
122		}
123
124	});
125
126	function close_sub_uls() {
127		menuContainerMobile.find('ul').each(function() {
128			var cur = cur;
129			var ul = $(this);
130			ul.removeClass('opened');
131			icon = ul.parent('li').find('.mobileExpand').first();
132			icon.removeClass('expanded');
133		});
134	}
135
136	/**
137	 * Sets or removes .focus class on an element.
138	 */
139	function toggleFocus() {
140		var self = this;
141
142		// Move up through the ancestors of the current link until we hit .nav-menu.
143		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
144
145			// On li elements toggle the class .focus.
146			if ( 'li' === self.tagName.toLowerCase() ) {
147				if ( -1 !== self.className.indexOf( 'focus' ) ) {
148					self.className = self.className.replace( ' focus', '' );
149				} else {
150					self.className += ' focus';
151				}
152			}
153
154			self = self.parentElement;
155		}
156	}
157
158	/**
159	 * Toggles `focus` class to allow submenu access on tablets.
160	 */
161	( function( mobileContainer ) {
162		var touchStartFn, i,
163			parentLink = mobileContainer.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
164
165		if ( 'ontouchstart' in window ) {
166			touchStartFn = function( e ) {
167				var menuItem = this.parentNode, i;
168
169				if ( ! menuItem.classList.contains( 'focus' ) ) {
170					e.preventDefault();
171					for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
172						if ( menuItem === menuItem.parentNode.children[i] ) {
173							continue;
174						}
175						menuItem.parentNode.children[i].classList.remove( 'focus' );
176					}
177					menuItem.classList.add( 'focus' );
178				} else {
179					menuItem.classList.remove( 'focus' );
180				}
181			};
182
183			for ( i = 0; i < parentLink.length; ++i ) {
184				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
185			}
186		}
187	}( mobileContainer ) );
188
189	//Sticky Nav
190	var scrolling = false;
191
192	window.addEventListener('scroll', function() {
193		scrolling = true;
194	});
195
196	setInterval( function() {
197		if ( scrolling ) {
198			scrolling = false;
199			diff = mobileContainer.offsetTop - window.pageYOffset;
200			if ( diff < 0 ) {
201				if (mobileContainer.className.indexOf( 'sticky-nav' ) == -1) {
202					mobileContainer.className += ' sticky-nav';
203				}
204			} else {
205				mobileContainer.className = mobileContainer.className.replace( ' sticky-nav', '' );
206			}
207		}
208	}, 100 );
209
210	//resize window open close menu
211	var resizing = false;
212
213	window.addEventListener('resize', function() {
214		resizing = true;
215	});
216
217	setInterval( function() {
218		if ( resizing ) {
219			resizing = false;
220			if (window.innerWidth > 1024) {
221				close_sub_uls();
222				body.className = body.className.replace(' mobile-menu-opened','');
223				mobileContainer.className = mobileContainer.className.replace( ' toggled', '' );
224				mobileNavContainer.className = mobileNavContainer.className.replace( ' show-mobile-menu', '' );
225				mobileButtonTop.className = mobileButtonTop.className.replace( 'toggled', '' );
226				// if(typeof mobileMenuContainer != 'undefined') {
227				// 	mobileMenuContainer.className = mobileMenuContainer.className.replace( ' toggled', '' );
228				// }
229
230				menuContainerMobile.parent()[0].className = menuContainerMobile.parent()[0].className.replace( ' toggled', '' );
231
232				buttonClick.className = buttonClick.className.replace( ' toggled', '' );
233				buttonClick.setAttribute( 'aria-expanded', 'false' );
234				mobileMenu.setAttribute( 'aria-expanded', 'false' );
235			}
236		}
237	}, 100 );
238
239
240	//search menu
241	$('.search-toggle-mobile').on('click',function() {
242		var search = $( this );
243		var searchBtn = search.find( 'div' );
244		var searchBox = $( '#search-container-mobile' );
245
246		search.toggleClass( 'active' );
247		searchBox.toggleClass( 'hide' );
248
249		if ( search.hasClass( 'active' ) ) {
250			searchBtn.attr( 'aria-expanded', 'true' );
251		} else {
252			searchBtn.attr( 'aria-expanded', 'false' );
253		}
254	});
255
256} )( 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.