PageSourceSearch

https://shropshirehillsdiscoverycentre.co.uk/includes/js/tvw-acc-menu.js?v=7

js shropshirehillsdiscoverycentre.co.uk collected 2026-09-26 15:04:10 UTC 9,096 bytes, 289 lines download raw bytes

1$(document).ready(function() {
2  	var switchAt = '1023px';
3	$('.nav').setup_navigation();
4	var $menu = $('#menu'),
5	$menulink = $('.menu-link'),
6	$menuTrigger = $('.has-subnav > a');
7	$menulink.focus(function(e) {
8		e.preventDefault();
9		$menulink.toggleClass('active');
10		$menu.toggleClass('active');
11	});
12	$menuTrigger.focus(function(e) {
13		e.preventDefault();
14		var $this = $(this);
15		$this.toggleClass('active').next('ul').toggleClass('active');
16	});
17	$('.has-subnav').mouseleave(function(e){
18		$(this).removeClass('show-menu');
19	});
20	$('.level-1-link').mouseleave(function(e){
21		$(this).children('ul,.mega-con').removeClass('show-menu');
22	});
23	//Mobile Menu Functionality
24	//burger functionality
25	$('#mobile-burger').on('click',function(e){
26		var $this = $(this);
27		var mencon = $('#site-mob-nav');
28		var parcon = $('#maf-nav-head');
29		if( $this.hasClass('active') ){
30			document.documentElement.classList.remove('no-scroll');
31			$this.removeClass('active').attr('aria-expended',false);
32			mencon.removeClass('expanded');
33			parcon.removeClass('menuopen');
34		}else{
35			document.documentElement.classList.add('no-scroll');
36			$this.addClass('active').attr('aria-expended',true);
37			mencon.addClass('expanded');
38			parcon.addClass('menuopen');
39		}
40	});
41	$('#burger-label').on('click',function(){
42		$('#mobile-burger').click();
43	});
44	$('#mobile-burger').keydown(function(e){
45		if($('#mobile-burger').hasClass('active')){
46		if(e.keyCode == 13 || e.keyCode == 32 || e.keyCode == 38 || e.keyCode == 37 || e.keyCode == 27){
47			e.preventDefault();
48			$(this).click();
49		}else if(e.keyCode == 40){
50			$('.mob-nav').children('li').first().find('a').first().focus();
51		}
52		}else{
53		if(e.keyCode == 13 || e.keyCode == 32 ||  e.keyCode == 40){
54			e.preventDefault();
55			$(this).click();
56		}
57		}
58	});
59	//close mobile menu on esc
60	$('#site-mob-nav .mob-nav a').keydown(function(e){
61		if(e.keyCode == 27){
62		e.preventDefault();
63		$('.mobile-burger').click().focus();
64		}
65	});
66
67	$('.mob-open-menu').on('click', function(e){
68		e.preventDefault();
69		$(this).siblings('ul').addClass('open');
70		$(this).next('ul').find('a').first().focus();
71	});
72	$('.mob-close-menu').on('click', function(e){
73		e.preventDefault();
74		$(this).closest('ul').removeClass('open');
75	});
76
77});
78
79var keyCodeMap = {
80  48:"0", 49:"1", 50:"2", 51:"3", 52:"4", 53:"5", 54:"6", 55:"7", 56:"8", 57:"9", 59:";",
81  65:"a", 66:"b", 67:"c", 68:"d", 69:"e", 70:"f", 71:"g", 72:"h", 73:"i", 74:"j", 75:"k", 76:"l",
82  77:"m", 78:"n", 79:"o", 80:"p", 81:"q", 82:"r", 83:"s", 84:"t", 85:"u", 86:"v", 87:"w", 88:"x", 89:"y", 90:"z",
83  96:"0", 97:"1", 98:"2", 99:"3", 100:"4", 101:"5", 102:"6", 103:"7", 104:"8", 105:"9"
84}
85
86$.fn.setup_navigation = function(settings) {
87
88	settings = jQuery.extend({
89		menuHoverClass: 'show-menu',
90	}, settings);
91
92	// Add ARIA role to menubar and menu items
93
94  $(this).attr('role', 'menubar').find('a').attr('role', 'menuitem');
95
96	var top_level_links = $(this).find('> li > a');
97
98	// Set tabIndex to -1 so that top_level_links can't receive focus until menu is open
99	$(top_level_links).next('ul')
100		//.attr('data-test','true')
101		.attr('role','menu')
102		.find('a')
103		.attr('tabIndex',-1);
104  $(top_level_links).next('.mega-con')
105		//.attr('data-test','true')
106		.attr('role','menu')
107		.find('a')
108		.attr('tabIndex',-1);
109
110	// Adding aria-haspopup for appropriate items
111	$(top_level_links).each(function(){
112		if($(this).next('ul').length > 0 || $(this).next('.mega-con').length > 0){
113      $(this).attr('aria-haspopup', true).attr('aria-expanded', false);
114      $(this).parent('li').addClass('has-subnav');
115    }
116	});
117
118	$(top_level_links).hover(function(){
119    if($(this).next('ul').length > 0 || $(this).next('.mega-con').length > 0){
120      $(this).attr('aria-expanded',true);
121    }
122		$(this).closest('ul')
123			.find('.'+settings.menuHoverClass)
124			.removeClass(settings.menuHoverClass)
125			.find('a')
126			.attr('tabIndex',-1);
127		$(this).next('ul')
128			.addClass(settings.menuHoverClass)
129			.find('a').attr('tabIndex',0);
130    $(this).next('.mega-con')
131			.addClass(settings.menuHoverClass)
132			.find('a').attr('tabIndex',0);
133	},function(){
134    if($(this).next('ul').length > 0 || $(this).next('.mega-con').length > 0){
135      $(this).attr('aria-expanded',false);
136    }
137  });
138
139  $(top_level_links).focus(function(){
140    $(top_level_links).each(function(){
141  		if($(this).next('ul').length > 0 || $(this).next('.mega-con').length > 0){
142        $(this).attr('aria-expanded', false);
143      }
144  	});
145    if($(this).next('ul').length > 0 || $(this).next('.mega-con').length > 0){
146      $(this).attr('aria-expanded',true);
147    }
148		$(this).closest('ul')
149			.find('.'+settings.menuHoverClass)
150			.removeClass(settings.menuHoverClass)
151			.find('a')
152			.attr('tabIndex',-1);
153    $(this).next('ul')
154			.addClass(settings.menuHoverClass)
155			.find('a').attr('tabIndex',0);
156    $(this).next('.mega-con')
157			.addClass(settings.menuHoverClass)
158			.find('a').attr('tabIndex',0);
159	});
160
161	// Bind arrow keys for navigation
162	$(top_level_links).keydown(function(e){
163		if(e.keyCode == 37) {
164			e.preventDefault();
165			// This is the first item
166			if($(this).parent('li').prev('li').length == 0) {
167				$(this).parents('ul').find('> li').last().find('a').first().focus();
168			} else {
169				$(this).parent('li').prev('li').find('a').first().focus();
170			}
171		} else if(e.keyCode == 38) {
172			e.preventDefault();
173			if($(this).parent('li').find('ul').length > 0) {
174				$(this).parent('li').find('ul')
175					.addClass(settings.menuHoverClass)
176					.find('a').attr('tabIndex',0)
177					.last().focus();
178			}
179		} else if(e.keyCode == 39) {
180			e.preventDefault();
181			// This is the last item
182			if($(this).parent('li').next('li').length == 0) {
183				$(this).parents('ul').find('> li').first().find('a').first().focus();
184			} else {
185				$(this).parent('li').next('li').find('a').first().focus();
186			}
187		} else if(e.keyCode == 40) {
188			e.preventDefault();
189			if($(this).parent('li').find('ul').length > 0) {
190				$(this).parent('li').find('ul')
191					.addClass(settings.menuHoverClass)
192					.find('a').attr('tabIndex',0)
193					.first().focus();
194			}
195		} else if(e.keyCode == 13 || e.keyCode == 32) {
196      e.preventDefault();
197      window.location = $(this).attr('href');
198		} else if(e.keyCode == 27) {
199			e.preventDefault();
200			$('.'+settings.menuHoverClass)
201				.removeClass(settings.menuHoverClass)
202				.find('a')
203				.attr('tabIndex',-1);
204		} else {
205			$(this).parents('ul').find('> li').each(function(){
206				if($(this).find('a').first().text().substring(0,1).toLowerCase() == keyCodeMap[e.keyCode]) {
207					$(this).find('a').first().focus();
208					return false;
209				}
210			});
211		}
212	});
213
214	var links = $(top_level_links).parent('li').find('ul').find('a');
215	$(links).keydown(function(e){
216		if(e.keyCode == 38) {
217			e.preventDefault();
218			// This is the first item
219			if($(this).parent('li').prev('li').length == 0) {
220				$(this).parents('ul').parents('li').find('a').first().focus();
221			} else {
222				$(this).parent('li').prev('li').find('a').first().focus();
223			}
224		} else if(e.keyCode == 39) {
225			e.preventDefault();
226      if($(this).parents('ul').first().parents('li').next('li').length){
227        $(this).parents('ul').first().parents('li').next('li').find('a').first().focus();
228      } else {
229        $(this).parents('ul').first().parents('li').find('a').first().focus();
230      }
231		} else if(e.keyCode == 40) {
232			e.preventDefault();
233			if($(this).parent('li').next('li').length == 0) {
234				$(this).parents('ul').parents('li').find('a').first().focus();
235			} else {
236				$(this).parent('li').next('li').find('a').first().focus();
237			}
238		} else if(e.keyCode == 27 || e.keyCode == 37) {
239			e.preventDefault();
240			$(this).parents('ul').first()
241			.parents('ul').first().find('.'+settings.menuHoverClass)
242			.removeClass(settings.menuHoverClass)
243			.find('a')
244			.attr('tabIndex',-1);
245      if($(this).parents('ul').first().parents('li').prev('li').length){
246        $(this).parents('ul').first().parents('li').prev('li').find('a').first().focus();
247      } else {
248        $(this).parents('ul').first().parents('li').find('a').first().focus();
249      }
250		} else if(e.keyCode == 32) {
251			e.preventDefault();
252			window.location = $(this).attr('href');
253		} else {
254			var found = false;
255			$(this).parent('li').nextAll('li').find('a').each(function(){
256				if($(this).text().substring(0,1).toLowerCase() == keyCodeMap[e.keyCode]) {
257					$(this).focus();
258					found = true;
259					return false;
260				}
261			});
262			if(!found) {
263				$(this).parent('li').prevAll('li').find('a').each(function(){
264					if($(this).text().substring(0,1).toLowerCase() == keyCodeMap[e.keyCode]) {
265						$(this).focus();
266						return false;
267					}
268				});
269			}
270		}
271	});
272
273
274	// Hide menu if click or focus occurs outside of navigation
275	$(this).find('a').last().keydown(function(e){
276		if(e.keyCode == 9) {
277			$('.'+settings.menuHoverClass)
278				.removeClass(settings.menuHoverClass)
279				.find('a')
280				.attr('tabIndex',-1);
281		}
282	});
283
284  $(document).click(function(){ $('.'+settings.menuHoverClass).removeClass(settings.menuHoverClass).find('a').attr('tabIndex',-1); });
285
286	$(this).click(function(e){
287		e.stopPropagation();
288	});
289}

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.