1 2function emptyLocationList() { 3 localStorage.removeItem('locationLists') 4 localStorage.removeItem('selectedTerms') 5 jQuery(`.button-route, .button-add-route`).removeClass('selected') 6 jQuery(`.button-route, .button-add-route`).find('span').remove() 7 if (jQuery('body').hasClass('page-template-page-map')) { 8 jQuery(`.button-route, .button-add-route`).append('<span>Lägg till</span>') 9 } else { 10 jQuery(`.button-route, .button-add-route`).append('<span>Lägg till i reseplaneraren</span>') 11 } 12 updateRPcounter() 13} 14 15function removeLocation(tab, locationId) { 16 let locationLists = localStorage.getItem('locationLists') 17 if (locationLists !== null) { 18 locationLists = JSON.parse(locationLists) 19 if (Array.isArray(locationLists[tab])) { 20 const index = locationLists[tab].findIndex(location => location.id = locationId); 21 if (index > -1) { 22 locationLists[tab].splice(index, 1); 23 localStorage.setItem('locationLists', JSON.stringify(locationLists)) 24 updateRPcounter() 25 jQuery(`.button-route[data-post=${locationId}], .button-add-route[data-post=${locationId}]`).removeClass('selected') 26 jQuery(`.button-route[data-post=${locationId}], .button-add-route[data-post=${locationId}]`).find('span').remove() 27 if (jQuery('body').hasClass('page-template-page-map')) { 28 jQuery(`.button-route[data-post=${locationId}], .button-add-route[data-post=${locationId}]`).append('<span>Lägg till</span>') 29 } else { 30 jQuery(`.button-route[data-post=${locationId}], .button-add-route[data-post=${locationId}]`).append('<span>Lägg till i reseplaneraren</span>') 31 } 32 } 33 } 34 } 35} 36 37function updateRPcounter() { 38 let locationLists = localStorage.getItem('locationLists') 39 const routeMenu = jQuery('.menu-item-route').find('.sub-menu') 40 routeMenu.empty() 41 if (locationLists !== null) { 42 locationLists = JSON.parse(locationLists) 43 let sum = 0 44 locationLists.forEach((tab, index) => { 45 sum = sum+tab.length 46 }) 47 jQuery('#route-count').html(sum) 48 locationLists.forEach((list) => { 49 list.forEach((location,index) => { 50 if (location !== null && location.hasOwnProperty('title') && location.hasOwnProperty('id')) { 51 let li = document.createElement('li') 52 li.classList.add('menu-item') 53 li.setAttribute('role', 'menuitem') 54 li.innerHTML = ` 55 <div class="route-item" id="route-item-${location.id}"> 56 <p class="route-item-title route-stop-activity"> 57 <button>${index+1}. ${location.title}</button> 58 </p> 59 <button class="route-item-remove" onclick="removeLocation(${index},${location.id})"></button> 60 </div> 61 ` 62 routeMenu.append(li) 63 } 64 65 }) 66 }) 67 let li = document.createElement('li') 68 li.classList.add('menu-item') 69 li.setAttribute('role', 'menuitem') 70 li.innerHTML = ` 71 <div class="route-empty"> 72 <button class="button selected" onclick="emptyLocationList()">Töm reseplaneraren</button> 73 </div> 74 ` 75 routeMenu.append(li) 76 } else { 77 jQuery('#route-count').html(0) 78 jQuery(`.button-route, .button-add-route`).removeClass('selected') 79 80 if(!jQuery(`.button-route, .button-add-route`).hasClass('button-add-route')) { 81 jQuery(`.button-route, .button-add-route`).find('span').remove() 82 if (jQuery('body').hasClass('page-template-page-map')) { 83 jQuery(`.button-route, .button-add-route`).append('<span>Lägg till</span>') 84 } else { 85 jQuery(`.button-route, .button-add-route`).append('<span>Lägg till i reseplaneraren</span>') 86 } 87 } 88 89 } 90} 91 92 93(function($){ 94 $(document).ready(function(){ 95 updateRPcounter(); 96 fetch('https://api.openweathermap.org/data/2.5/weather?q=nybro&units=metric&appid=5aa12df5c1c051305c71151b4d5def1a').then((result) => { 97 return result.json() 98 }).then((result) => { 99 console.log(result) 100 $('#temperature').html(Math.round(result.main.temp)+"<span>°C</span>") 101 $('#temperature').removeClass('loader') 102 $('#temperature').addClass("temp-"+result.weather[0].icon) 103 }) 104 document.querySelectorAll('.autoplay-video').forEach((el) => el.play()) 105 $('.button-route, .button-add-route').each(async function() { 106 const locationId = $( this ).data('post') 107 let locationLists = localStorage.getItem('locationLists') 108 if (locationLists !== null) { 109 locationLists = JSON.parse(locationLists) 110 let selectedLocationsById = []
111 locationLists.forEach((list, tabindex) => { 112 // get all selected locations id and store them in a one dimensional array 113 selectedLocationsById = selectedLocationsById.concat(locationLists[tabindex].map(function(el) { 114 // gets corresponding 'column' 115 if (el !== null && el.hasOwnProperty('id')) return el['id']; 116 return undefined 117 // removes undefined values 118 }).filter(function(el) { return typeof el != 'undefined'; })); 119 }) 120 if (selectedLocationsById.indexOf(locationId) > -1) { 121 // this location is already in the locationList, give its button the selected class 122 $(this).addClass('selected') 123 $(this).find('span').remove() 124 if ($('body').hasClass('page-template-page-map')) { 125 $(this).append('<span>Ta bort</span>') 126 } else { 127 $(this).append('<span>Ta bort från reseplaneraren</span>') 128 } 129 } 130 } 131 }) 132 133 $('.button-route, .button-add-route').on('click', async function(e) { 134 e.preventDefault() 135 const locationId = $( this ).data('post') 136 console.log('location ',locationId) 137 var locationLists = localStorage.getItem('locationLists'); 138 if (locationLists == null) { 139 locationLists = [] 140 } else { 141 locationLists = JSON.parse(localStorage.getItem('locationLists')) 142 } 143 let selectedLocationsById = [] 144 locationLists.forEach((list, tabindex) => { 145 // get all selected locations id and store them in a one dimensional array 146 selectedLocationsById = selectedLocationsById.concat(locationLists[tabindex].map(function(el) { 147 // gets corresponding 'column' 148 if (el !== null && el.hasOwnProperty('id')) return el['id']; 149 return undefined 150 // removes undefined values 151 }).filter(function(el) { return typeof el != 'undefined'; })); 152 }) 153 154 if (selectedLocationsById.indexOf(locationId) > -1) { 155 // this location is already in the locationList, remove it. 156 locationLists.forEach((list, tabindex) => { 157 var removeIndex = list.map(item => item.id).indexOf(locationId); 158 ~removeIndex && list.splice(removeIndex, 1); 159 }) 160 $(this).removeClass('selected') 161 $(this).find('span').remove() 162 if (jQuery('body').hasClass('page-template-page-map')) { 163 $(this).append('<span>Lägg till</span>') 164 } else { 165 $(this).append('<span>Lägg till i reseplaneraren</span>') 166 } 167 168 169 } else { 170 const locationResponse = await fetch(KREATION_VARS.ajaxurl+"?action=get_location_by_id", { 171 method: 'POST', 172 headers: { 173 'Content-Type': 'application/x-www-form-urlencoded' 174 }, 175 body: new URLSearchParams({ 176 'action' : 'get_location_by_id', 177 'id' : locationId 178 }) 179 }) 180 const location = await locationResponse.json() 181 const totalMinutesTabs = [] 182 locationLists.forEach((list, tabindex) => { 183 if (list.length > 0 ) { 184 totalMinutesTabs[tabindex] = list.reduce((a, b) => a + ((b !== null && b.hasOwnProperty('time')) ? b['time'] || 0 : 0), 0); 185 } else { 186 // if this tab is empty it should not be here, delete it 187 locationLists.splice(tabindex, 1); 188 } 189 190 }) 191 let tabToPutNewLocationOn = -1
192 totalMinutesTabs.forEach((minutes, tabindex) => { 193 // check if adding this location would take a trip more than four hours to complete 194 if (location !== null && location.hasOwnProperty('time') && location.time+minutes <= (4*60)) { 195 tabToPutNewLocationOn = tabindex 196 } 197 198 }) 199 200 if (tabToPutNewLocationOn === -1) { 201 if (!Array.isArray(locationLists[locationLists.length-1])) { 202 locationLists.push([]) 203 } 204 locationLists[locationLists.length-1].push(location) 205 } else { 206 locationLists[tabToPutNewLocationOn].push(location) 207 } 208 $(this).addClass('selected') 209 $(this).find('span').remove() 210 if ($('body').hasClass('page-template-page-map')) { 211 $(this).append('<span>Ta bort</span>') 212 } else { 213 $(this).append('<span>Ta bort från reseplaneraren</span>') 214 } 215 } 216 localStorage.setItem('locationLists', JSON.stringify(locationLists)) 217 updateRPcounter(); 218 }) 219 /* Navigation sticky */ 220 var aboveHeight = 2; 221 $(window).scroll(function () { 222 if ($(window).scrollTop() > aboveHeight) { 223 $("#navigation").addClass("minimized").next(); 224 } else { 225 $("#navigation").removeClass("minimized").next(); 226 } 227 }); 228 /* END Navigation sticky */ 229 230 231 /* SmartPhoto Gallery */ 232 $smartPhoto = $(".js-smartphoto"); 233 if($smartPhoto && typeof $smartPhoto.SmartPhoto === "function") { 234 $smartPhoto.SmartPhoto(); 235 } 236 /* END SmartPhoto Gallery */ 237 238 /* Fitvids */ 239 $(".card").fitVids(); 240 $(".wp-block-embed-youtube").fitVids(); 241 /* END Fitvids */ 242 243 /*SUPER SIMPLE ACCORDION, CHECK CHRISTOFFERS WCAG VERSION*/ 244 $('.accordion-trigger').click(function() { 245 /*Find body*/ 246 $body = $('#' + $(this).attr('aria-controls')); 247 if($body) { 248 $accordionTrigger = $(this); 249 $body.toggle(10, function() { 250 $body.is(':hidden') ? $accordionTrigger.attr('aria-expanded', false) : $accordionTrigger.attr('aria-expanded', true); 251 }); 252 } 253 }); 254 255 /*DROPDOWN A11Y MENU, CHECK AND ADD*/ 256 257 /* ALL SLICK SLIDERS USED */ 258 /*------------------------*/ 259 /* Slick sliders if exist on page */ 260 $defaultSlidesEl = $('.slideshow'); 261 if($defaultSlidesEl && typeof $defaultSlidesEl.slick === "function") { 262 $defaultSlidesEl.slick({ 263 autoplay: true, 264 autoplaySpeed: 10000, 265 adaptiveHeight: true 266 }); 267 $defaultSlidesEl.slick('setPosition'); 268 } 269 270 /* Header slideshow with slick */ 271 $headerSlidesEl = $('.header-slideshow'); 272 if($headerSlidesEl && typeof $headerSlidesEl.slick === "function") { 273 $headerSlidesEl.slick({ 274 autoplay: true, 275 autoplaySpeed: 10000, 276 adaptiveHeight: true 277 }); 278 $headerSlidesEl.slick('setPosition'); 279 } 280 281 /* Guthenberg slider for object pages */ 282 $gallerySlidesEl = $('.slideshow-gallery'); 283 if($gallerySlidesEl && typeof $gallerySlidesEl.slick === "function") { 284 $gallerySlidesEl.slick({ 285 autoplay: false, 286 autoplaySpeed: 10000, 287 adaptiveHeight: true, 288 fade: true 289 }); 290 $gallerySlidesEl.slick('setPosition'); 291 } 292 293 /* Glasswork slideshow with slick */ 294 $glassworkSlidesEl = $('#glasswork .glasswork-slideshow'); 295 console.log($glassworkSlidesEl) 296 if($glassworkSlidesEl && typeof $glassworkSlidesEl.slick === "function") { 297 $glassworkSlidesEl.slick({ 298 infinite: true, 299 dots: false, 300 slidesToShow: 4, 301 slidesToScroll: 4, 302 responsive: [ 303 { 304 breakpoint: 1600, 305 settings: { 306 slidesToShow: 3, 307 slidesToScroll: 3 308 } 309 }, 310 { 311 breakpoint: 1200, 312 settings: { 313 infinite: false, 314 slidesToShow: 3.1, 315 slidesToScroll: 3 316 } 317 }, 318 { 319 breakpoint: 1024, 320 settings: { 321 infinite: false, 322 slidesToShow: 2.1, 323 slidesToScroll: 2 324 } 325 }, 326 { 327 breakpoint: 600, 328 settings: { 329 infinite: false, 330 slidesToShow: 1.1, 331 slidesToScroll: 1 332 } 333 } 334 ] 335 }); 336 $glassworkSlidesEl.slick('setPosition'); 337 } 338 339 /* Events slideshow with slick */ 340 $eventsSlidesEl = $('#events .events-slideshow'); 341 if($eventsSlidesEl && typeof $eventsSlidesEl.slick === "function") { 342 $eventsSlidesEl.slick({ 343 infinite: true, 344 dots: false,
345 arrows: false, 346 slidesToShow: 4, 347 slidesToScroll: 4, 348 responsive: [ 349 { 350 breakpoint: 1200, 351 settings: { 352 infinite: false, 353 slidesToShow: 3.1, 354 slidesToScroll: 3 355 } 356 }, 357 { 358 breakpoint: 1024, 359 settings: { 360 infinite: false, 361 slidesToShow: 2.1, 362 slidesToScroll: 2 363 } 364 }, 365 { 366 breakpoint: 600, 367 settings: { 368 infinite: false, 369 slidesToShow: 1.1, 370 slidesToScroll: 1 371 } 372 } 373 ] 374 }); 375 $eventsSlidesEl.slick('setPosition'); 376 } 377 378 /* Videos slideshow with slick */ 379 $videosSlidesEl = $('.videos-slideshow'); 380 if($videosSlidesEl && typeof $videosSlidesEl.slick === "function") { 381 $videosSlidesEl.slick({ 382 infinite: true, 383 dots: false, 384 arrows: true, 385 slidesToShow: 2, 386 slidesToScroll: 2, 387 responsive: [ 388 { 389 breakpoint: 1200, 390 settings: { 391 infinite: false, 392 slidesToShow: 2.1, 393 slidesToScroll: 2 394 } 395 }, 396 { 397 breakpoint: 600, 398 settings: { 399 infinite: false, 400 slidesToShow: 1.1, 401 slidesToScroll: 1 402 } 403 } 404 ] 405 }); 406 $videosSlidesEl.slick('setPosition'); 407 } 408 409 /* Blogg slideshow with slick */ 410 $bloggSlidesEl = $('.blogg-slideshow'); 411 if($bloggSlidesEl && typeof $bloggSlidesEl.slick === "function") { 412 $bloggSlidesEl.slick({ 413 infinite: true, 414 dots: false, 415 arrows: true, 416 slidesToShow: 3, 417 slidesToScroll: 3, 418 responsive: [ 419 { 420 breakpoint: 1200, 421 settings: { 422 infinite: false, 423 slidesToShow: 3.1, 424 slidesToScroll: 3 425 } 426 }, 427 { 428 breakpoint: 1024, 429 settings: { 430 infinite: false, 431 slidesToShow: 2.1, 432 slidesToScroll: 2 433 } 434 }, 435 { 436 breakpoint: 600, 437 settings: { 438 infinite: false, 439 slidesToShow: 1.1, 440 slidesToScroll: 1 441 } 442 } 443 ] 444 }); 445 $bloggSlidesEl.slick('setPosition'); 446 } 447 448 /* Related slideshow with slick */ 449 $relatedSlidesEl = $('#related .related-slideshow'); 450 if($relatedSlidesEl && typeof $relatedSlidesEl.slick === "function") { 451 $relatedSlidesEl.slick({ 452 infinite: true, 453 dots: false, 454 arrows: false, 455 slidesToShow: 4, 456 slidesToScroll: 4, 457 responsive: [ 458 { 459 breakpoint: 1200, 460 settings: { 461 infinite: false, 462 slidesToShow: 3.1, 463 slidesToScroll: 3 464 } 465 }, 466 { 467 breakpoint: 1024, 468 settings: { 469 infinite: false, 470 slidesToShow: 2.1, 471 slidesToScroll: 2 472 } 473 }, 474 { 475 breakpoint: 600, 476 settings: { 477 infinite: false, 478 slidesToShow: 1.1, 479 slidesToScroll: 1 480 } 481 } 482 ] 483 }); 484 $relatedSlidesEl.slick('setPosition'); 485 } 486 487 488 $('.slick-prev').attr('tabIndex', '3'); 489 $('.slick-next').attr('tabIndex', '4'); 490 491 /* END ALL SLICK SLIDERS USED */ 492 /*----------------------------*/ 493 494 /* Init mmenu, use default title if in frontend development, if not KREATION_VARS is set*/ 495 let title = '<img src="../images/logotype_mmenu.svg" alt="Company Name">'; 496 if (typeof KREATION_VARS !== 'undefined') { 497 title = '<img src="'+KREATION_VARS.themeurl+'/assets/images/logotype_mmenu.svg" alt="'+KREATION_VARS.sitename+'">'; 498 } 499 $("#menu").mmenu( { 500 "extensions": [ 501 "pagedim-black", 502 "position-back", 503 "multiline", 504 "theme-black", 505 "position-right" 506 ], 507 "setSelected": { 508 "parent": false, 509 "hover": true, 510 "current": "detect" 511 }, 512 "keyboardNavigation": { 513 enable : true, 514 enhance : true 515 }, 516 "navbar": { 517 "title": title, 518 }, 519 "navbars": [ 520 { 521 "position": "top", 522 "content": [ 523 "prev", 524 "title", 525 "close" 526 ], 527 "title": title, 528 }, 529 { 530 "position": "bottom", 531 "content": [ 532 '<div id="google_translate_element_mm" class="translate-box"></div>' 533 ] 534 } 535 ] 536 }); 537 /* End MMEnu*/ 538 539 //MM Fix no href on link elements 540 $("nav#menu a").each(function(i) { 541 if(typeof $(this).attr('href') === 'undefined') { 542 $(this).attr('href','#'); 543 console.log($(this)); 544 } 545 }); 546 547 //Close cookie bar 548 $("#cookie_consent").click(function() { 549 setCookie('_kreation_consent',true,7); 550 $("#kreation-cookie-consent").slideUp(); 551 }); 552 553 // Setup the a11y nav 554 $('#navigation').setup_navigation(); 555 // RWD Nav Pattern 556 $('body').addClass('js'); 557 var $menu = $('#navigation'), 558 // $menulink = $('.menu-link'), 559 $menuTrigger = $('.menu-item-has-children > a'); 560 $menuTrigger.click(function(e) { 561 var $this = $(this); 562 $this.toggleClass('active').next('ul').toggleClass('active'); 563 }); 564 }); 565 566 var keyCodeMap = { 567 48:"0", 49:"1", 50:"2", 51:"3", 52:"4", 53:"5", 54:"6", 55:"7", 56:"8", 57:"9", 59:";", 568 65:"a", 66:"b", 67:"c", 68:"d", 69:"e", 70:"f", 71:"g", 72:"h", 73:"i", 74:"j", 75:"k", 76:"l", 569 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", 570 96:"0", 97:"1", 98:"2", 99:"3", 100:"4", 101:"5", 102:"6", 103:"7", 104:"8", 105:"9" 571 } 572 jQuery.fn.setup_navigation = function(settings) { 573 settings = jQuery.extend({ 574 menuHoverClass: 'show-menu', 575 }, settings); 576 // Add ARIA role to menubar and menu items 577 $(this).attr('role', 'menubar').find('li').attr('role', 'menuitem'); 578 var top_level_links = $(this).find('li.menu-item-has-children > a'); 579 $(this).on('mouseleave','.'+settings.menuHoverClass,function() { 580 console.log('is element there? '+$(this).find('#google_translate_element').length) 581 if ($(this).find(settings.menuHoverClass).length === 0) { 582 if ($(this).find('input[type=text]').length=== 0 && $(this).find('#google_translate_element').length === 0) { 583 $(this).removeClass(settings.menuHoverClass) 584 .attr('aria-hidden', 'true') 585 .attr('tabIndex',-1); 586 } 587 588 } 589 }) 590 $(top_level_links).next('ul') 591 .attr('data-test','true') 592 .attr({ 'aria-hidden': 'true', 'role': 'menu' }) 593 .find('a') 594 .attr('tabIndex',-1); 595 // Adding aria-haspopup for appropriate items 596 $(top_level_links).each(function(){ 597 if($(this).next('ul').length > 0) 598 $(this).parent('li').attr('aria-haspopup', 'true'); 599 }); 600 $(top_level_links).hover(function(){ 601 $(this).closest('ul') 602 .attr('aria-hidden', 'false') 603 .find('.'+settings.menuHoverClass) 604 .attr('aria-hidden', 'true') 605 .removeClass(settings.menuHoverClass) 606 .find('a') 607 .attr('tabIndex',-1); 608 $(this).next('ul') 609 .attr('aria-hidden', 'false') 610 .addClass(settings.menuHoverClass) 611 .find('a').attr('tabIndex',0); 612 }); 613 $('.menu-item > a').focus(function() { 614 if ($(this).closest('ul').hasClass('level-1')) { 615 $(this).closest('ul').find('.show-menu').each(function() { 616 $(this).attr('aria-hidden', 'true') 617 .removeClass(settings.menuHoverClass) 618 .find('a') 619 .attr('tabIndex',-1); 620 }) 621 } 622 }) 623 $(top_level_links).focus(function(){ 624 // close any open menus 625 if ($(this).closest('ul').hasClass('level-1')) { 626 $(this).closest('ul').find('.show-menu').each(function() { 627 $(this).attr('aria-hidden', 'true') 628 .removeClass(settings.menuHoverClass) 629 .find('a') 630 .attr('tabIndex',-1); 631 }) 632 } else { 633 $(this).closest('ul') 634 // Removed by Terrill 635 // The following was adding aria-hidden="false" to root ul since menu is never hidden 636 // and seemed to be causing flakiness in JAWS (needs more testing) 637 // .attr('aria-hidden', 'false') 638 .find('.'+settings.menuHoverClass) 639 .attr('aria-hidden', 'true') 640 .removeClass(settings.menuHoverClass) 641 .find('a') 642 .attr('tabIndex',-1); 643 $(this).find('.show-menu').each(function() { 644 $(this).attr('aria-hidden', 'true') 645 .removeClass(settings.menuHoverClass) 646 .find('a') 647 .attr('tabIndex',-1); 648 }) 649 } 650 $(this).next('ul') 651 .attr('aria-hidden', 'false') 652 .addClass(settings.menuHoverClass) 653 .find('a').attr('tabIndex',0); 654 }); 655 // Bind arrow keys for navigation 656 $(top_level_links).keydown(function(e){ 657 if(e.keyCode == 37) { 658 e.preventDefault(); 659 // This is the first item 660 if($(this).parent('li').prev('li').length == 0) { 661 $(this).parents('ul').find('> li').last().find('a').first().focus(); 662 } else { 663 $(this).parent('li').prev('li').find('a').first().focus(); 664 } 665 } else if(e.keyCode == 38) { 666 e.preventDefault(); 667 if($(this).parent('li').find('ul').length > 0) { 668 $(this).parent('li').find('ul') 669 .attr('aria-hidden', 'false') 670 .addClass(settings.menuHoverClass) 671 .find('a').attr('tabIndex',0) 672 .last().focus(); 673 } 674 } else if(e.keyCode == 39) { 675 if ($(this).closest('li').hasClass('menu-item-has-children')) { 676 // if this is a subitem check if theres a submenu to move to 677 console.log('this should move to submenu') 678 $(this).closest('li').find('ul').first().find('> li').first().find('a').first().focus(); 679 console.log($(this).closest('li')) 680 console.log($(this).closest('li').find('ul').first()) 681 console.log($(this).closest('li').find('ul').first().find('> li').first()) 682 console.log($(this).closest('li').find('ul').first().find('> li').first().find('a').first()) 683 } else if($(this).parent('li').next('li').length == 0) { 684 $(this).parents('ul').find('> li').first().find('a').first().focus(); 685 } else { 686 $(this).parent('li').next('li').find('a').first().focus(); 687 } 688 } else if(e.keyCode == 40) { 689 e.preventDefault(); 690 if($(this).parent('li').find('ul').length > 0) { 691 $(this).parent('li').find('ul') 692 .attr('aria-hidden', 'false') 693 .addClass(settings.menuHoverClass) 694 .find('a').attr('tabIndex',0) 695 .first().focus(); 696 } 697 } else if(e.keyCode == 13 || e.keyCode == 32) { 698 // If submenu is hidden, open it 699 e.preventDefault(); 700 $(this).parent('li').find('ul[aria-hidden=true]') 701 .attr('aria-hidden', 'false') 702 .addClass(settings.menuHoverClass) 703 .find('a').attr('tabIndex',0) 704 .first().focus(); 705 } else if(e.keyCode == 27) { 706 e.preventDefault(); 707 $('.'+settings.menuHoverClass) 708 .attr('aria-hidden', 'true') 709 .removeClass(settings.menuHoverClass) 710 .find('a') 711 .attr('tabIndex',-1); 712 } else { 713 $(this).parent('li').find('ul[aria-hidden=false] a').each(function(){ 714 if($(this).text().substring(0,1).toLowerCase() == keyCodeMap[e.keyCode]) { 715 $(this).focus(); 716 return false;
717 } 718 }); 719 } 720 }); 721 var links = $(top_level_links).parent('li').find('ul').find('a'); 722 $(links).keydown(function(e){ 723 if(e.keyCode == 38) { 724 e.preventDefault(); 725 // This is the first item 726 if($(this).parent('li').prev('li').length == 0) { 727 $(this).parents('ul').parents('li').find('a').first().focus(); 728 } else { 729 $(this).parent('li').prev('li').find('a').first().focus(); 730 } 731 } else if(e.keyCode == 40) { 732 e.preventDefault(); 733 if($(this).parent('li').next('li').length == 0) { 734 $(this).parents('ul').parents('li').find('a').first().focus(); 735 } else { 736 $(this).parent('li').next('li').find('a').first().focus(); 737 } 738 } else if(e.keyCode == 27) { 739 e.preventDefault(); 740 console.log($(this) 741 .parents('ul').first() 742 .prev('a').focus() 743 .parents('ul').first().find('.'+settings.menuHoverClass)) 744 $(this) 745 .parents('ul').first() 746 .prev('a').focus() 747 .parents('ul').first().find('.'+settings.menuHoverClass) 748 .attr('aria-hidden', 'true') 749 .removeClass(settings.menuHoverClass) 750 .find('a') 751 .attr('tabIndex',-1); 752 } else if (e.keyCode == 37) { 753 $(this).parent('li').parent('ul').parent('li').find('a').first().focus() 754 } else if(e.keyCode == 32) { 755 e.preventDefault(); 756 window.location = $(this).attr('href'); 757 } else { 758 var found = false; 759 $(this).parent('li').nextAll('li').find('a').each(function(){ 760 if($(this).text().substring(0,1).toLowerCase() == keyCodeMap[e.keyCode]) { 761 $(this).focus(); 762 found = true; 763 return false; 764 } 765 }); 766 if(!found) { 767 $(this).parent('li').prevAll('li').find('a').each(function(){ 768 if($(this).text().substring(0,1).toLowerCase() == keyCodeMap[e.keyCode]) { 769 $(this).focus(); 770 return false; 771 } 772 }); 773 } 774 } 775 }); 776 $('.menu-item > a').keydown(function(e) { 777 if(e.keyCode == 39) { 778 e.preventDefault(); 779 // top-level item move to the next top-level item 780 console.log($(this).closest('ul')) 781 if ($(this).closest('ul').hasClass('level-1')) { 782 console.log('this should move to next menu') 783 $(this).closest('li').next().find('a').first().focus() 784 } 785 } else if (e.keyCode == 37) { 786 e.preventDefault(); 787 if ($(this).closest('ul').hasClass('level-1')) { 788 $(this).closest('li').prev().find('a').first().focus() 789 } 790 } 791 }) 792 // Hide menu if click or focus occurs outside of navigation 793 $(this).find('a').last().keydown(function(e){ 794 if(e.keyCode == 9) { 795 // If the user tabs out of the navigation hide all menus 796 $('.'+settings.menuHoverClass) 797 .attr('aria-hidden', 'true') 798 .removeClass(settings.menuHoverClass) 799 .find('a') 800 .attr('tabIndex',-1); 801 } 802 }); 803 $(document).click(function(){ $('.'+settings.menuHoverClass).attr('aria-hidden', 'true').removeClass(settings.menuHoverClass).find('a').attr('tabIndex',-1); }); 804 $(this).click(function(e){ 805 e.stopPropagation(); 806 }); 807 } 808 809}(jQuery)); 810 811 812function setCookie(name,value,days) { 813 var expires = ""; 814 if (days) { 815 var date = new Date(); 816 date.setTime(date.getTime() + (days*24*60*60*1000)); 817 expires = "; expires=" + date.toUTCString(); 818 } 819 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 820} 821 822 823function getDeviceType() { 824 const ua = navigator.userAgent; 825 if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) { 826 return "tablet"; 827 } 828 else if (/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(ua)) { 829 return "mobile"; 830 } 831 return "desktop"; 832}
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.