1/* TABLE OF CONTENTS 21. Global functions 32. Menu 4 2.1 Menu trigger 5 2.2 Keyboard nav 6 2.3 Mobile menu trigger 7 2.4 Hover Intent 8 2.5 Search trigger 9 2.6 Menu Item Classes 10 2.7 Menu Section Colors 11 2.8 Section Nav hidden 123. Components 13 3.1 Accordions 14 3.2 Scrollable tables 15 3.3 Hidden sidebar 16 3.4 Tiny Slider 17 3.5 Categorized tiles 18 3.6 Mobile Related Content 19 3.7 Email subscribe placeholder 204. Window resize 21 4.1 Scrollable tables 22 4.2 Cookie Consent banner 23 4.3 Mobile menu 245. Storage 25 5.1 Alerts banner 26 5.2 Categorized tiles 276. Ajax 287. Resolutions year select 29*/ 30 31(function ($) { 32 33 /* [ 1. Global functions ] ----------*/ 34 35 function delayAdd(elem,className,transition) { 36 setTimeout( 37 function removeAddFunc() { 38 elem.addClass(className); 39 }, 40 transition); 41 } 42 function delayRemove(elem,className,transition) { 43 setTimeout( 44 function removeDelayFunc() { 45 elem.removeClass(className); 46 }, 47 transition); 48 } 49 50 /* [ 2. Menu ] ----------*/ 51 52 /* [ 2.1 Menu trigger ] ----------*/ 53 $('.a-menu-link-wrapper__trigger, .a-section-menu-link-wrapper__trigger').on('click',function(){ 54 $(this).attr('aria-expanded',function(index,attr){ 55 return attr == 'false' ? 'true' : 'false'; 56 }).attr('aria-label',function(index,attr){ 57 if(attr.indexOf('Expand the') > -1) { 58 return attr.replace('Expand the', 'Collapse the') 59 } else { 60 return attr.replace('Collapse the', 'Expand the') 61 } 62 }); 63 $(this).parent().siblings('.m-menu').slideToggle(); 64 $(this).parent().parent().siblings().find('.a-menu-link-wrapper__trigger, .a-section-menu-link-wrapper__trigger').attr('aria-expanded',false).attr('aria-label',function(index,attr){ 65 if(attr.indexOf('Collapse the') > -1) { 66 return attr.replace('Collapse the', 'Expand the') 67 } 68 }).parent().siblings('.m-menu').slideUp(); 69 }); 70 $(document).on('focusin',function(){ 71 setTimeout(function(){ 72 if($(window).width() > 1024 &! $('*:focus').parents('.m-menu-wrapper--main').length) { 73 $('.m-menu-wrapper--main nav > .m-menu .m-menu').slideUp(); 74 $('.m-menu-wrapper--main nav .a-menu-link-wrapper__trigger').attr('aria-expanded',false).attr('aria-label',function(index,attr){ 75 if(attr.indexOf('Collapse the') > -1) { 76 return attr.replace('Collapse the', 'Expand the') 77 } 78 }); 79 } 80 },200); 81 }); 82 83 /* [ 2.2 Keyboard nav ] ----------*/ 84 $('.m-menu-wrapper--main a').keyNavMenus(); 85 $('.t-sidebar .m-menu a').keyNavMenus({ 86 menuLinkClass:'.a-section-menu-link-wrapper__link', 87 triggerClass:'.a-section-menu-link-wrapper__trigger' 88 }); 89 $('.m-menu-wrapper--header nav a, .m-menu--footer nav a').keyNavMenus({ 90 menuItemClass:'.m-menu__item', 91 menuLinkClass: '.m-menu__item-link', 92 singleLevel: true 93 }); 94 95 /* [2.3 Mobile menu trigger ] ----------*/ 96 $('.a-menu-trigger').on('click',function(){ 97 $('.a-menu-trigger').attr('aria-label',function(index,attr){ 98 if ($('.a-menu-trigger').attr('aria-expanded') == 'false') { 99 return attr.replace('Expand the','Collapse the'); 100 } 101 else { 102 return attr.replace('Collapse the','Expand the'); 103 } 104 }) 105 $('.m-search-form').fadeOut(); 106 if($(window).width() <= 1234) { 107 $(this).attr('aria-expanded',function(index,attr){ 108 return attr == 'true' ? 'false' : 'true'; 109 }); 110 $('#'+$(this).attr('aria-controls')).slideToggle().attr('aria-hidden',function(index,attr){ 111 return attr == 'true' ? 'false' : 'true'; 112 }); 113 if($(this).attr('aria-expanded') == 'true') { 114 115 $('.m-menu--mobile_wrapper').fadeIn(); 116 117 $('.m-menu-wrapper--main .m-menu__item--active-trail').each(function(){ 118 $(this).find('> .m-menu__item-link-wrapper > .a-menu-link-wrapper__trigger').attr('aria-expanded',true).attr('aria-label',function(index,attr){ 119 return attr.replace('Expand the','Collapse the'); 120 }).parent().siblings('.m-menu').show(); 121 }); 122 } 123 else { 124 $('.m-menu--mobile_wrapper').fadeOut(); 125 } 126 } 127 }); 128 129 /* [2.4 Hover intent ] ----------*/ 130 $('.t-header--desktop .menu--main > .m-menu .m-menu__item--expanded').hoverIntent({ 131 interval: 100, 132 over: mainmenuOn, 133 timeout: 100, 134 out: mainmenuOff 135 }); 136 function mainmenuOn() { 137 $(this).find('> .m-menu').slideDown('fast'); 138 139 }; 140 function mainmenuOff() { 141 $(this).find('> .m-menu').slideUp('fast'); 142 } 143 144 145 146 /* [2.5 Search Toggle ] ----------*/ 147 $('.a-search-trigger').click(function(){ 148 if ($(window).width() > 1234) { 149 if ($(this).attr('aria-expanded') == 'false') { 150 $('.a-search-trigger').attr('aria-expanded', 'true'); 151 $('.t-header__menu-search .m-search-form').addClass('active').fadeIn(); 152 $('.t-header__menu-search .m-search-form .js-form-item input').focus(); 153 $('.t-header--desktop .region-menu').attr('aria-hidden', 'true').hide(); 154 } 155 else { 156 $('.a-search-trigger').attr('aria-expanded', 'false'); 157 $('.t-header__menu-search .m-search-form').removeClass('active').fadeOut(); 158 $('.t-header--desktop .region-menu').attr('aria-hidden', 'false').fadeIn(); 159 } 160 } 161 else { 162 $('.t-header--mobile .m-menu--mobile_wrapper').fadeOut(); 163 $('.t-header--mobile .a-menu-trigger').attr('aria-expanded', 'false'); 164 $('.t-header--mobile .a-menu-trigger').attr('aria-label', 'Expand the mobile menu'); 165 if ($(this).attr('aria-expanded') == 'false') { 166 $('.a-search-trigger').attr('aria-expanded', 'true'); 167 $('.t-header__menu-search .m-search-form').addClass('active').fadeIn(); 168 $('.t-header__menu-search .m-search-form .js-form-item input').focus(); 169 } 170 else { 171 $('.a-search-trigger').attr('aria-expanded', 'false'); 172 $('.t-header__menu-search .m-search-form').removeClass('active').fadeOut(); 173 } 174 } 175 }) 176 $('#block-ubcm-exposedformsearch-solrpage-1-2 input').attr("placeholder", "Search . . ."); 177 178 179 /* [2.6 Menu Item Classes ] ----------*/ 180 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/25"]').length) { 181 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/25"]').parent().addClass("members"); 182 } 183 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/26"]').length) { 184 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/26"]').parent().addClass("council") 185 } 186 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/27"]').length) { 187 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/27"]').parent().addClass("policy") 188 $('.t-header--desktop .a-menu-link-wrapper__link[data-drupal-link-system-path="node/27"]').html('Policy<br>Areas'); 189 } 190 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/28"]').length) { 191 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/28"]').parent().addClass("funding") 192 } 193 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/29"]').length) { 194 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/29"]').parent().addClass("about") 195 } 196 197 /* [2.7 Menu Section Colors ] ----------*/ 198 if (!$('body').hasClass("home")) { 199 $('.menu--main > .m-menu > .m-menu__item').addClass('greyscale'); 200 $('.m-menu__item--active-trail').removeClass('greyscale'); 201 } 202 203 if ( $('.t-header--desktop .menu--main > .m-menu > .m-menu__item--active-trail').length === 0 ) { 204 $('nav > .m-menu > .m-menu__item').removeClass('greyscale'); 205 } 206 207 $( ".t-header--desktop .menu--main > .m-menu > .m-menu__item" ) 208 .on( "mouseenter", function() { 209 if ($('.home').length || !$('.t-header--desktop .menu--main > .m-menu > .m-menu__item--active-trail').length) { 210 $(this).siblings().addClass('greyscale'); 211 } 212 else { 213 $(this).removeClass('greyscale'); 214 } 215 } ) 216 .on( "mouseleave", function() { 217 if ($('.home').length || !$('.t-header--desktop .menu--main > .m-menu > .m-menu__item--active-trail').length) { 218 $('.t-header--desktop .m-menu__item').removeClass('greyscale'); 219 } 220 else if (!$(this).hasClass('m-menu__item--active-trail')) { 221 $(this).addClass('greyscale'); 222 } 223 } ); 224 225 226 /* [2.8 Section Nav hidden ] ----------*/ 227 if($('.region-sidebar .m-menu--section').children(':visible').length == 0) { 228 $('#block-ubcm-mainnavigation-2').hide(); 229 } 230 231 /* [ 3. Components ] ----------*/ 232 233 /* [ 3.1 Accordions ] ----------*/ 234 $('.field--name-field-accordion > .field__item').each(function(){ 235 var itemIndex = $(this).index(); 236 $(this).find('*[data-acc-id]').each(function(){ 237 var currentID = $(this).attr('id'); 238 $(this).attr('id','accordion__group-'+itemIndex+'-'+currentID); 239 }); 240 }); 241 $('.o-accordion-group > li').each(function(){ 242 var itemIndex = $(this).index(); 243 $(this).find('*[data-acc-id]').each(function(){ 244 var currentID = $(this).attr('id'); 245 $(this).attr('id',currentID+itemIndex); 246 }); 247 }); 248 $('.m-accordion__trigger').on('click',function(){ 249 $(this).toggleClass('is-open').attr('aria-expanded',function(index,attr){ 250 return attr == 'true' ? 'false' : 'true'; 251 }); 252 $(this).siblings('.m-accordion__content').slideToggle().attr('aria-hidden',function(index,attr){ 253 return attr == 'true' ? 'false' : 'true'; 254 }); 255 $(this).parents('.o-accordion-group__list-row').siblings().find('.m-accordion__trigger').removeClass('is-open').attr('aria-expanded',false).siblings().slideUp(); 256 }); 257 if($('.o-accordion-group__list-row').length) { 258 $('.o-accordion-group__list-row').each(function(){ 259 if(!$(this).find('.m-accordion__trigger').length){ 260 $(this).hide(); 261 } 262 }); 263 } 264 if($('.field--name-field-accordion > .field__item').length) { 265 $('.field--name-field-accordion > .field__item').each(function(){ 266 if(!$(this).find('.m-accordion__trigger').length){ 267 $(this).hide(); 268 } 269 }); 270 } 271 var hash = window.location.hash; 272 if(hash && hash.indexOf('accordion') !== -1 && $(hash).length){ 273 /* auto expand on accordion hash in URL */ 274 $(hash).click(); 275 } 276 277 /* [ 3.2 Scrollable tables ] ----------*/ 278 $('.t-content table').each(function() { 279 var element = $(this); 280 // Create the wrapper element
281 var scrollWrapper = $('<div />', { 282 'class': 'scrollable', 283 'html': '<div tabindex="0" role="region" />' // The inner div is needed for styling 284 }).insertBefore(element); 285 // Store a reference to the wrapper element 286 element.data('scrollWrapper', scrollWrapper); 287 // Move the scrollable element inside the wrapper element 288 element.appendTo(scrollWrapper.find('div')); 289 }); 290 291 /* [ 3.3 Hidden sidebar ] ----------*/ 292 if($('.t-sidebar .region-sidebar > *').length < 0 || $('.t-sidebar.t-sidebar--no-nav .region-sidebar > *:not(.block-menu)').length < 0) { 293 $('.t-sidebar').addClass('t-sidebar--hidden'); 294 $('.t-content').addClass('t-content--fullwidth'); 295 } 296 297 /* [ 3.4 Tiny Slider ] ----------*/ 298 if($('.region-carousel .m-carousel--multiple').length) { 299 var carousel = tns({ 300 container: '.m-carousel--multiple .m-carousel__slide-wrapper', 301 nav: true, 302 navContainer: '.m-carousel--multiple .a-carousel-nav', 303 controls: true, 304 mode: 'gallery', 305 prevButton: '.m-carousel--multiple .a-carousel-control--previous', 306 nextButton: '.m-carousel--multiple .a-carousel-control--next', 307 }); 308 if ($(window).width() > 1024) { 309 var carousel_controls_position; 310 setTimeout(function(){ 311 carousel_controls_position = ($('.m-carousel--multiple .tns-slide-active .m-carousel-slide__image').height() - $('.m-carousel--multiple .m-carousel__controls').outerHeight()); 312 $('.m-carousel--multiple .m-carousel__controls').attr('style','top:'+carousel_controls_position+'px').addClass('m-carousel__controls--visible'); 313 },100); 314 carousel.events.on('indexChanged',function(){ 315 setTimeout(function(){ 316 carousel_controls_position = ($('.m-carousel--multiple .tns-slide-active .m-carousel-slide__image').height() - $('.m-carousel--multiple .m-carousel__controls').outerHeight()); 317 $('.m-carousel--multiple .m-carousel__controls').attr('style','top:'+carousel_controls_position+'px'); 318 },100); 319 }); 320 } 321 else { 322 $('.region-carousel .a-carousel-control').on( "click", function() { 323 if($('.m-carousel--multiple').length) { 324 setTimeout(function(){ 325 $height = $('.region-carousel .tns-slide-active').outerHeight(); 326 $heightInteger = parseFloat($height, 10); 327 $heightInteger = $heightInteger - 60; 328 $('.m-carousel--multiple .a-carousel-controls').attr('style','top:'+$heightInteger+'px').addClass('a-carousel-controls--visible'); 329 },100); 330 } 331 }) 332 } 333 } 334 if($('.o-alerts-banner__carousel-slides .views-row').length > 1) { 335 $('.o-alerts-banner__carousel-slides .views-row').each(function(){ 336 $('.o-alerts-banner .a-carousel-nav').append('<li class="a-carousel-nav__item"><button class="a-carousel-nav__item-button"></button></li>'); 337 }); 338 $('.o-alerts-banner .a-carousel-controls').removeClass('a-carousel-controls--hidden'); 339 var alerts_carousel = tns({ 340 container:'.o-alerts-banner__carousel-slides .view-content', 341 nav: false, 342 prevButton: '.o-alerts-banner .a-carousel-control--previous', 343 nextButton: '.o-alerts-banner .a-carousel-control--next', 344 }); 345 } 346 347 /* [ 3.5 Categorized tiles ] ----------*/ 348 // This is covered in section 5.2 with the use of sessionStorage. 349 // For some implementations, such as a user selecting their 'profile', it makes sense to remember that choice. 350 // For others, it doesn't make sense to store that value. 351 // This should be assessed based on the recommended use of the categorized tiles field on a project-by-project basis. 352 if($('.a-category-list__button').length) { 353 $('.a-category-list__item:first > .a-category-list__button').addClass('a-category-list__button--selected'); 354 $('.o-categorized-tiles__categories--mobile').val($('.o-categorized-tiles__categories--mobile option:first').val()); 355 $('.o-categorized-tiles__content .o-categorized-tiles__section:first').addClass('o-categorized-tiles__section--active'); 356 } 357 $('.a-category-list__button').on('click',function(){ 358 $(this).addClass('a-category-list__button--selected').parent().siblings().find('.a-category-list__button').removeClass('a-category-list__button--selected'); 359 $('.o-categorized-tiles__categories--mobile').val($(this).attr('data-category')); 360 $('.o-categorized-tiles__section[data-category="'+$(this).attr('data-category')+'"]').addClass('o-categorized-tiles__section--active').siblings().removeClass('o-categorized-tiles__section--active'); 361 }); 362 $('.o-categorized-tiles__categories--mobile').on('change',function(){ 363 $('.a-category-list__button[data-category="'+$(this).val()+'"]').addClass('a-category-list__button--selected').parent().siblings().find('.a-category-list__button').removeClass('a-category-list__button--selected'); 364 $('.o-categorized-tiles__section[data-category="'+$(this).val()+'"]').addClass('o-categorized-tiles__section--active').siblings().removeClass('o-categorized-tiles__section--active'); 365 }); 366 367 /* [ 3.6 Mobile Related Content ] ----------*/ 368 if ( ($('.view-related-contact').children().length < 1) && ($('#block-related-links-mobile').children().length < 1) ) { 369 $('.t-sidebar--mobile').hide(); 370 } 371 else { 372 if ($(window).width() < 1024) { 373 $('.t-sidebar--mobile').show(); 374 } 375 } 376 if ($('.m-sidebar--mobile__trigger').length) { 377 $('.m-sidebar--mobile__trigger').click(function(){ 378 if ($(this).attr('aria-expanded') == 'false') { 379 $('.m-sidebar--mobile__content').slideDown(); 380 $(this).attr('aria-expanded', 'true'); 381 $(this).attr('aria-label', 'Collapse Related Content'); 382 } 383 else { 384 $('.m-sidebar--mobile__content').slideUp(); 385 $(this).attr('aria-expanded', 'false'); 386 $(this).attr('aria-label', 'Expand Related Content'); 387 } 388 }) 389 } 390 391 /* [ 3.7 Email Subscribe Placeholder ] ----------*/ 392 if ($('.o-newsletter-block__form').length) { 393 $('.o-newsletter-block__form input').attr('placeholder', ' Your Email Address'); 394 } 395 396 /* [ 3.8 Resolutions Database ] ----------*/ 397 if ($('.p-nid--129').length) { 398 $slug = window.location.pathname; 399 $query = window.location.search; 400 if ( ($slug == '/convention-resolutions/resolutions/resolutions-database') && ($query.length < 1) ) { 401 $('.view-resolutions .view-content').hide(); 402 $('.view-resolutions .view-header').hide(); 403 $('.view-resolutions nav').hide(); 404 } 405 } 406 407 /* [ 3.9 Banner Video Controls ] ----------*/
408 if ($('.m-carousel-slide video').length) { 409 $('.m-carousel-slide video').each(function(){ 410 $(this).prop("controls", false).prop("loop", true); 411 $(this).after('<button class="button video-btn paused" title="Play Video"><span class="play"><span class="fas fa-play"></span> Play Video</span><span class="pause"><span class="fas fa-pause"></span> Pause Video</span></button>'); 412 }) 413 $('.video-btn').click(function(){ 414 if ($(this).hasClass('paused')) { 415 $(this).parent().find('video').trigger('play'); 416 $('.video-btn').attr('title', 'Pause Video') 417 } else { 418 $(this).parent().find('video').trigger('pause'); 419 $('.video-btn').attr('title', 'Play Video') 420 } 421 $(this).toggleClass('paused'); 422 }) 423 } 424 425 /* [ 4. Window resize ] ----------*/ 426 427 var resizeTimer; 428 function resizeFunction() { 429 /* [ 4.1 Scrollable tables ] ----------*/ 430 if($('.scrollable').length) { 431 $('.scrollable').each(function(){ 432 if ($(this).find('> div > table').not('table.sticky-header').outerWidth() > $(this).find('> div > table').not('table.sticky-header').parent().outerWidth()) { 433 $(this).find('> div > table').not('table.sticky-header').data('scrollWrapper').addClass('has-scroll'); 434 } else { 435 $(this).find('> div > table').not('table.sticky-header').data('scrollWrapper').removeClass('has-scroll'); 436 } 437 }); 438 } 439 /* [ 4.2 Cookie Consent banner ] ----------*/ 440 if($('.cc_banner-wrapper').length) { 441 $('body').css('padding-bottom',$('.cc_banner-wrapper').outerHeight()); 442 } 443 /* [ 4.3 Mobile menu ] ----------*/ 444 if($(window).width() > 1234) { 445 $('.a-menu-trigger').attr('aria-expanded',false); 446 $('.a-menu-trigger').attr('aria-label','Expand the mobile menu'); 447 $('.t-header--mobile .m-menu--mobile_wrapper').hide(); 448 $('.m-menu-wrapper').show().attr('style',''); 449 } 450 else { 451 452 } 453 /* [ 4.4 Tiny Slider ] ----------*/ 454 if ($(window).width() > 1024) { 455 if($('.m-carousel--multiple').length) { 456 setTimeout(function(){ 457 carousel_controls_position = ($('.m-carousel--multiple .tns-slide-active .m-carousel-slide__image').height() - $('.m-carousel--multiple .a-carousel-controls').outerHeight()); 458 $('.m-carousel--multiple .a-carousel-controls').attr('style','top:'+carousel_controls_position+'px').addClass('a-carousel-controls--visible'); 459 },200); 460 } 461 } 462 else { 463 if($('.m-carousel--multiple').length) { 464 setTimeout(function(){ 465 $height = $('.region-carousel .tns-slide-active').outerHeight(); 466 $heightInteger = parseFloat($height, 10); 467 $heightInteger = $heightInteger - 60; 468 $('.m-carousel--multiple .a-carousel-controls').attr('style','top:'+$heightInteger+'px').addClass('a-carousel-controls--visible'); 469 },200); 470 } 471 } 472 /* [ 4.5 Mobile Sidebar ] ----------*/ 473 if ($(window).width() > 1024) { 474 $(".t-sidebar--mobile").hide(); 475 } 476 else { 477 if ( ($('.view-related-contact').children().length) || ($('#block-related-links-mobile').children().length) ) { 478 $(".t-sidebar--mobile").show(); 479 } 480 } 481 }; 482 $(window).on('load resize',function() { 483 clearTimeout(resizeTimer); 484 resizeTimer = setTimeout(resizeFunction, 250); 485 }); 486 resizeFunction(); 487 488 /* [ 5. Storage ] ----------*/ 489 490 if ('sessionStorage' in window && typeof sessionStorage == 'object') { 491 $(document).ready(function() { 492 /* [ 5.1 Alerts banner ] ----------*/ 493 if($('.o-alerts-banner').length) { 494 if(sessionStorage['alerts'] == 'collapsed') { 495 $('.m-alert__meta').hide().attr('aria-hidden',true); 496 $('.a-alerts-trigger').attr({ 497 title:'Expand the Alerts carousel', 498 'aria-expanded':false 499 }).text('Open'); 500 if($('.o-alerts-banner .views-row').length > 1) { 501 $('.o-alerts-banner .a-carousel-controls').addClass('a-carousel-controls--hidden'); 502 } 503 } else { 504 sessionStorage['alerts'] = 'expanded'; 505 $('.m-alert__meta').show().attr('aria-hidden',true); 506 $('.a-alerts-trigger').attr({ 507 title:'Collapse the Alerts carousel', 508 'aria-expanded':true 509 }).text('Close'); 510 if($('.o-alerts-banner .views-row').length > 1) { 511 $('.o-alerts-banner .a-carousel-controls').removeClass('a-carousel-control
511s--hidden'); 512 } 513 } 514 $('.a-alerts-trigger').on('click',function(){ 515 $(this).attr({ 516 'title':function(index,attr) { 517 return attr == 'Expand the Alerts carousel' ? 'Collapse the Alerts carousel' : 'Expand the Alerts carousel'; 518 }, 519 'aria-expanded':function(index,attr) { 520 return attr == 'true' ? 'false' : 'true'; 521 } 522 }).text(function(index,text){ 523 return text == 'Close' ? 'Open' : 'Close'; 524 }); 525 $('.m-alert__meta').slideToggle().attr('aria-hidden',function(index,attr){ 526 return attr == 'true' ? 'false' : 'true'; 527 }); 528 if($('.o-alerts-banner .views-row').length > 1) { 529 $('.o-alerts-banner .a-carousel-controls').toggleClass('a-carousel-controls--hidden'); 530 } 531 if($(this).attr('aria-expanded') == 'true') { 532 sessionStorage['alerts'] = 'expanded'; 533 } else { 534 sessionStorage['alerts'] = 'collapsed'; 535 } 536 }); 537 } 538 539 /* [ 5.2 Categorized tiles ] ----------*/ 540 // This is covered in section 3.5 without the use of sessionStorage. 541 // For some implementations, such as a user selecting their 'profile', it makes sense to remember that choice. 542 // For others, it doesn't make sense to store that value. 543 // This should be assessed based on the recommended use of the categorized tiles field on a project-by-project basis. 544 // if($('.a-category-list__button').length) { 545 // if(sessionStorage['categorized tiles'] == null || sessionStorage['categorized tiles'] == '') { 546 // sessionStorage['categorized tiles'] = $('.a-category-list__item:first > .a-category-list__button').attr('data-category'); 547 // } 548 // $('.a-category-list__button[data-category="'+sessionStorage['categorized tiles']+'"]').addClass('a-category-list__button--selected'); 549 // $('.o-categorized-tiles__categories--mobile').val(sessionStorage['categorized tiles']); 550 // $('.o-categorized-tiles__section[data-category="'+sessionStorage['categorized tiles']+'"]').addClass('o-categorized-tiles__section--active'); 551 // } 552 // $('.a-category-list__button').on('click',function(){ 553 // sessionStorage['categorized tiles'] = $(this).attr('data-category'); 554 // $(this).addClass('a-category-list__button--selected').parent().siblings().find('.a-category-list__button').removeClass('a-category-list__button--selected'); 555 // $('.o-categorized-tiles__categories--mobile').val(sessionStorage['categorized tiles']); 556 // $('.o-categorized-tiles__section[data-category="'+sessionStorage['categorized tiles']+'"]').addClass('o-categorized-tiles__section--active').siblings().removeClass('o-categorized-tiles__section--active'); 557 // }); 558 // $('.o-categorized-tiles__categories--mobile').on('change',function(){ 559 // sessionStorage['categorized tiles'] = $(this).val(); 560 // $('.a-category-list__button[data-category="'+sessionStorage['categorized tiles']+'"]').addClass('a-category-list__button--selected').parent().siblings().find('.a-category-list__button').removeClass('a-category-list__button--selected'); 561 // $('.o-categorized-tiles__section[data-category="'+sessionStorage['categorized tiles']+'"]').addClass('o-categorized-tiles__section--active').siblings().removeClass('o-categorized-tiles__section--active'); 562 // }); 563 }); 564 }; 565 566})(jQuery); 567 568/* [ 6. Ajax ] ----------*/ 569jQuery(document).ready(function ($) { 570 $(document).ajaxComplete(function () { 571 572 /* [ Menu Item Classes (BIGPIPE WORK AROUND) ] ----------*/ 573 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/25"]').length) { 574 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/25"]').parent().addClass("members"); 575 } 576 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/26"]').length) { 577 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/26"]').parent().addClass("council") 578 } 579 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/27"]').length) { 580 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/27"]').parent().addClass("policy") 581 $('.t-header--desktop .a-menu-link-wrapper__link[data-drupal-link-system-path="node/27"]').html('Policy<br>Areas'); 582 } 583 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/28"]').length) { 584 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/28"]').parent().addClass("funding") 585 } 586 if ($('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/29"]').length) { 587 $('.a-menu-link-wrapper__link[data-drupal-link-system-path="node/29"]').parent().addClass("about") 588 } 589 }); 590 591 /* [ Hover intent (BIGPIPE WORK AROUND) ] ----------*/ 592 //2.4 Hover intent 593 $('.t-header--desktop .menu--main > .m-menu .m-menu__item--expanded').hoverIntent({ 594 interval: 100, 595 over: mainmenuOn, 596 timeout: 100, 597 out: mainmenuOff 598 }); 599 function mainmenuOn() { 600 $(this).find('> .m-menu').slideDown('fast'); 601 602 }; 603 function mainmenuOff() { 604 $(this).find('> .m-menu').slideUp('fast'); 605 } 606 ///2.7 Menu Section Colors 607 if (!$('body').hasClass("home")) { 608 $('.menu--main > .m-menu > .m-menu__item').addClass('greyscale'); 609 $('.m-menu__item--active-trail').removeClass('greyscale'); 610 } 611 612 if ( $('.t-header--desktop .menu--main > .m-menu > .m-menu__item--active-trail').length === 0 ) { 613 $('nav > .m-menu > .m-menu__item').removeClass('greyscale'); 614 } 615 616 $( ".t-header--desktop .menu--main > .m-menu > .m-menu__item" ) 617 .on( "mouseenter", function() { 618 if ($('.home').length || !$('.t-header--desktop .menu--main > .m-menu > .m-menu__item--active-trail').length) { 619 $(this).siblings().addClass('greyscale'); 620 } 621 else { 622 $(this).removeClass('greyscale'); 623 } 624 } ) 625 .on( "mouseleave", function() { 626 if ($('.home').length || !$('.t-header--desktop .menu--main > .m-menu > .m-menu__item--active-trail').length) { 627 $('.t-header--desktop .m-menu__item').removeClass('greyscale'); 628 } 629 else if (!$(this).hasClass('m-menu__item--active-trail')) { 630 $(this).addClass('greyscale'); 631 } 632 } ); 633}); 634 635/* [ 7. Resolutions year select ] ----------*/ 636(function (Drupal, $) { 637 'use strict'; 638 639 /** 640 * Shared function to limit select options based on year rows from a view. 641 * 642 * @param {Object} context - The DOM context to search within. 643 * @param {string} viewSelector - Selector for the main view container. 644 * @param {string} yearRowsSelector - Selector for the year rows list. 645 * @param {string}
645 selectSelector - Selector for the select element(s) to limit. 646 * @param {string} dataKey - Unique data attribute key for processing flag. 647 */ 648 function limitYearSelect(context, viewSelector, yearRowsSelector, selectSelector, dataKey) { 649 // Early exit if the view is not present. 650 if ($(viewSelector, context).length === 0) { 651 return; 652 } 653 654 var $tidSelect = $(selectSelector, context); 655 var $yearRows = $(yearRowsSelector, context); 656 657 if ($tidSelect.length === 0 || $yearRows.length === 0) { 658 return; 659 } 660 661 if ($tidSelect.data(dataKey)) { 662 return; 663 } 664 665 $tidSelect.data(dataKey, true); 666 667 var allowedValues = []; 668 var allowedTexts = []; 669 670 $yearRows.each(function () { 671 var $row = $(this); 672 var value = null; 673 var text = $row.text().trim(); 674 675 if ($row.attr('data-tid')) { 676 value = $row.attr('data-tid'); 677 } 678 else if ($row.find('a').length) { 679 var href = $row.find('a').first().attr('href'); 680 if (href) { 681 var match = href.match(/[?&]tid=([^&]+)/); 682 if (match && match[1]) { 683 value = decodeURIComponent(match[1]); 684 } 685 } 686 } 687 else if (/^\d+$/.test(text)) { 688 value = text; 689 } 690 691 if (value !== null && allowedValues.indexOf(value) === -1) { 692 allowedValues.push(value); 693 } 694 695 if (text && allowedTexts.indexOf(text) === -1) { 696 allowedTexts.push(text); 697 } 698 }); 699 700 if (allowedValues.length === 0 && allowedTexts.length === 0) { 701 return; 702 } 703 704 $tidSelect.each(function () { 705 var $select = $(this); 706 $select.find('option').each(function () { 707 var $option = $(this); 708 var optionValue = $option.val(); 709 var optionText = $option.text().trim(); 710 711 if (optionValue === '' || optionValue === 'All') { 712 return; 713 } 714 715 var valueMatch = allowedValues.length > 0 && allowedValues.indexOf(optionValue) !== -1; 716 var textMatch = allowedTexts.length > 0 && allowedTexts.indexOf(optionText) !== -1; 717 718 if (valueMatch || textMatch) { 719 $option.show(); 720 } else { 721 $option.hide(); 722 } 723 }); 724 }); 725 } 726 727 /** 728 * Limits #edit-tid select options to values from view-resolutions-years-list. 729 */ 730 Drupal.behaviors.limitResolutionsYearSelect = { 731 attach: function (context, settings) { 732 limitYearSelect( 733 context, 734 '.view-resolutions', 735 '.view-resolutions-years-list .view-content .views-row', 736 '.view-resolutions [id^="edit-tid"]', 737 'limit-resolutions-year-select-processed' 738 ); 739 } 740 }; 741 742 /** 743 * Limits #edit-tid select options to values from view-resolution-response-years-list. 744 */ 745 Drupal.behaviors.limitResolutionResponseYearSelect = { 746 attach: function (context, settings) { 747 limitYearSelect( 748 context, 749 '.view-resolution-response', 750 '.view-resolution-response-years-list .view-content .views-row', 751 '.view-resolution-response [id*="years-target-id"]', 752 'limit-resolution-response-year-select-processed' 753 ); 754 } 755 }; 756 757})(Drupal, 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.