(function($){ var scrollWidth = parseInt(window.innerWidth-$(window).width()), maxTileH = 0, dev = false; $(document).ready(function () { // Handle Custom Accessible drowdowns if($('.custom-acc-dropdown-wrapper').length) { $('.custom-acc-dropdown-wrapper').on('click', '.custom-acc-selected-item', function(e){ if(dev){ console.log('-- custom-acc-selected-item CLICK');} var list = $(this).next(); if(list.is(":visible")){ if(dev){console.log('hide list');} list.hide().attr('aria-hidden','true'); }else{ if(dev){console.log('show list');} list.show().attr('aria-hidden','false'); } }); $('.custom-acc-dropdown-wrapper').on('keydown', '.custom-acc-selected-item', function(e){ if(dev){ console.log('-- custom-acc-selected-item KEYDOWN'); console.log(e.keyCode);} var list = $(this).next(); if(e.keyCode == 13){ // On Enter if(list.is(":visible")) { if(dev){console.log('hide list');} list.hide().attr('aria-hidden','true'); }else{ if(dev){console.log('show list');} list.show().attr('aria-hidden','false'); } } }); $('.custom-acc-dropdown-wrapper').on('blur', 'a', function(e){ if(dev){ console.log('a blur'); console.log(this); console.log(document.activeElement); } }); } initSearchBoxHandler(); //sticky header stickyHeader(); initResizeEventListeners(); initTabsClickHandlers(); initAccordionsClickHandlers(); initMainMenuClickHandling(); initAdditionalMenuClickHandling(); initMobileDropdownHandling(); var lateralItem = '.tabs-and-progress .lateral-nav-item'; lateralNavHeight(lateralItem); $(window).resize(function() { windowW = $(this).width(); lateralNavHeight(lateralItem); }); }); function stickyHeader() { var windowW = $(window).width(); if (windowW > (1279 - scrollWidth)) { $('.bottom-header').scrollToFixed( { zIndex: 100, preFixed: function() { // Execute just before going to sticky mode $(this).css({ "background": "black", "padding": "0", marginTop: 0 }); $('.main-menu').css({ top: "0" }); if(dev){ console.log('= PreFixed'); console.log($(window).height()); } $('.main-menu').height($(window).height()); }, postFixed: function() { // Execute just before going out of sticky mode $(this).css({ "background": "", "padding": "", marginTop: 20, zIndex: 9999 }); $('.main-menu').css({ top: "" }); $('.main-menu').height($(window).height() - 90); } }); // Handle transition between sticky and non-sticky mode $(window).on( "scroll", function(e){ var doc = document.documentElement; var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); if(top < 90){ $('.main-menu').height($(window).height() - 90 + top); } }); } } function calculateInnerWrapWidth() { var wrapperW = $('.wrapper').width(), windowW = $(window).width(); if (windowW > (1279 - scrollWidth)) { if ($('html').hasClass('js-nav')) { $('.inner-wrap').width(wrapperW - 300); $('.header-links').width(windowW - 300); } else { $('.inner-wrap').width(wrapperW); $('.header-links').width(windowW); } } else { var mainMenuW = $('.main-menu').width(); if ($('html').hasClass('js-nav')) { $('.header-links').width(windowW - mainMenuW); } else { $('.header-links').width(windowW); } } } function calculateWrapWidth() { var wrapperW = $('body').width(), windowW = $(window).width(); if (windowW > (1279 - scrollWidth)) { if ($('html').hasClass('js-nav')) { $('.inner-wrapper').width(wrapperW - 300); $('.header-links').width(windowW - 300); } else { $('.inner-wrapper').width(wrapperW); $('.header-links').width(windowW); } } else { var mainMenuW = $('.main-menu').width(); if ($('html').hasClass('js-nav')) { $('.header-links').width(windowW - mainMenuW); } else { $('.header-links').width(windowW); } } } function calculateHeight() { var $images = $('.three-tile-wrap .tile.image'), maxH = 0; $images.each(function (index) { var $currentImg = $(this).find('img'), currentH = 0; currentH = $currentImg.outerHeight(true); if (maxH < currentH) { maxH = currentH } }); $('.three-tile-wrap .tile').height(maxH); if (maxTileH < maxH) { maxTileH = maxH + 2; } } // Function that get URL parameter function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); if (sParameterName[0] == sParam) { return sParameterName[1]; } } } // Function shows tab content. It can receive two kind of parameters, tab ID or tab index ('tab1', 1). function showTab(tab) { if(tab.length){ var newTab = $(); var tabId = 'tab'; // If length is longer than 3 character, than parameter is like 'tab1' format, else it is just index like '1' if(tab.length > 3){ tabId = tab; }else{ tabId += tab; } newTab = $('a[href="#' + tabId + '"]'); if(!$('body.forward-look-page').length){ // Click new tab newTab[0].click(); } } } function initSearchBoxHandler(){ $('.search-input').hide(); // Toggle search input field $('.btn.search').click(function(e){ $('.search-input').toggle(); }); //On Click show search box $('.header-links .btn.search').click(function () { $(this).parents('.search-field').toggleClass('active'); if($(this).parents('.search-field').hasClass('active')){ $('#edit-search-block-form--2').focus(); } }); } function initTabsClickHandlers(){ // Tabs click handling $('.tab-content').hide(); $('ul.tabs li:first').addClass('selected').show(); $('.tab-content:first').show(); //On Click $('ul.tabs li').click(function (e) { e.preventDefault ? e.preventDefault() : e.returnValue = false; $('ul.tabs li').removeClass('selected'); $(this).addClass('selected'); $('.tab-content').hide(); var activeTab = $(this).find('a').attr('href'); $(activeTab).show(); }); // --- Accordion / Tab section handling (Investing in innovation page) var tabSection = '.tab-section-wrap .item .tab-head .tab-section-title'; $(tabSection).click(function (e) { e.preventDefault(); if ($(window).width() < 767) { if (!$(this).parent().hasClass('open')) { $('.tab-section-wrap .item').find('.tab-section').slideUp('fast'); $('.tab-section-wrap .item .tab-section-title.open').removeClass('open'); $(this).parent().addClass('open'); $(this).parent().next().slideDown('fast'); } else { $(this).parent().removeClass('open'); $(this).parent().next().slideUp('fast'); } } }); //first accrodion item is initially open $(tabSection).first().click(); // Handle tabs clicking (adding aria-selected and aria-hidden) if($('.tabs > li > a').length){ $('.tabs > li > a').on('click', function(e){ var targetId = $(this).attr('href').replace('#',''); // Set deselect all tab links $('.tabs > li > a').attr('aria-selected',false); // Set select to current link $(this).attr('aria-selected',true); // Set all tabs to aria-hidden="true" $('.tab-content').attr('aria-hidden',true); // Set aria-hidden="false" to active tab $('#'+targetId).attr('aria-hidden', false); }); } // Handle tab parameter in url, and open that tab by index var tabSelection = getUrlParameter('tab'); if (tabSelection && tabSelection.length) { showTab(tabSelection); } } function initAccordionsClickHandlers(){ // Accordions handler var heading = '.accordion .item .accordion-head a'; if(heading.length) { $(heading).click(function (e) { e.preventDefault(); if (!($('.jsmetrics:visible').length && $(window).width() > 786)) { if ($(this).parent().hasClass('open')) { $(this).parent().removeClass('open'); $(this).parent().next().slideUp('fast'); // Add aria attributes $(this).attr('aria-extended',false); $(this).parent().next().attr('aria-hidden',true); } else { $('.accordion .item').find('.accordion-content').slideUp('fast').attr('aria-hidden', true); $('.accordion .item .accordion-head.open').removeClass('open').attr('aria-extended', false); $(this).parent().addClass('open'); $(this).parent().next().slideDown('fast'); // Add aria attributes $(this).attr('aria-extended',true); $(this).parent().next().attr('aria-hidden',false); } } }); //first accrodion item is initially open $(heading).first().click(); } } function initMainMenuClickHandling(){ var heading = '.main-menu .item'; $(heading).click(function (e) { e.preventDefault(); if (!$(this).parent().hasClass('open')) { $('.main-menu .sub-section').find('.sec-level').slideUp('fast'); $('.main-menu .sub-section.open').removeClass('open'); $(this).parent().addClass('open'); $(this).next().slideDown('fast'); } else { $(this).parent().removeClass('open'); $(this).next().slideUp('fast'); } }); // Handle Main menu expandable second click $('.main-menu>.menu-inner>ul>li:has(ul:not(.open))>a').click(function(e){ e.preventDefault(); if(!$(this).next().hasClass('open')){ $('.sec-level.open').slideUp('fast').removeClass('open'); $(this).next().slideDown('fast').addClass('open'); } else { $('.sec-level').slideUp('fast').removeClass('open'); } }); // Handle Main menu active states $('.main-menu>.menu-inner>ul a.active').each(function(a,b){ var parentLi = $(this).parent(); parentLi.addClass('active'); if(parentLi.parent().hasClass('sec-level')){ parentLi.parent().parent().addClass('active'); parentLi.parent().show().addClass('open'); } }); $('.header .bottom-header .menu').click(function() { if($(window).width() > 1280) { $('.menu-inner').jScrollPane({ autoReinitialise: true, autoReinitialiseDelay: 10, mouseWheelSpeed: 20 }); }else{ $('.main-menu').height($('html').height()); } calculateInnerWrapWidth(); }); } function initAdditionalMenuClickHandling(){ // Handle OurProgrammes menu var ourProgrammesAdditionalMenu = $('.header-links .jsprogrames_additional_menu'); if(ourProgrammesAdditionalMenu.length && $('.header-links .newListSelected').length){ $('.header-links .newListSelected').click(function(e){ var urlSelected = $('.jsprogrames_additional_menu option:contains("' + $(this).find('.selectedTxt:eq(0)').html().replace('&','&') + '"):eq(0)').val(); window.location.href = window.location.origin + "/" + urlSelected; }); // Handle selection bug $('.header-links .newListSelected').keydown(function(e){ var key = 0; if (window.event) { key = window.event.keyCode; } else if (e) { key = e.keyCode; } if(key == 9 && e.shiftKey){ // Shift + Tab $('.btn.search:eq(0)').focus(); }else if(key == 9){ // Tab $('.btn.annual-report:eq(0)').focus(); }else if(key == 13){ // Enter var urlSelected = $('.header-links .jsprogrames_additional_menu option:contains("' + $(this).find('.selectedTxt:eq(0)').html().replace('&','&') + '"):eq(0)').val(); //jQuery('.header-links .SSContainerDivWrapper').show().find('li a:eq(0)').focus(); window.location.href = window.location.origin + "/" + urlSelected; //e.preventDefault(); } }); } // Add ARIA attributes to additional menu, if present if( $('.header-links .newList').length){ $('.header-links .selectedTxt').attr('aria-haspopup',true); $('.header-links .newList').attr('aria-label', 'submenu'); $('.header-links .newListSelected').attr('aria-describedby','additional-menu-description'); } } function initMobileDropdownHandling(){ // Handle mobile dropdown var mobileDropdown = $('.section-wrap .mobile-visible .custom-select'); mobileDropdown.on('change', function(e) { var valueSelected = this.value; if(valueSelected.length){ showTab(valueSelected); } e.preventDefault(); }); } function initResizeEventListeners(){ window.addEventListener('resize', stickyHeader); if (!($.browser.msie && parseInt($.browser.version, 10) <= 9)) { window.addEventListener('resize', calculateInnerWrapWidth); window.addEventListener('resize', calculateWrapWidth); } } // lateral navigation height function lateralNavHeight(navigation) { var windowW = $(window).width(); var maxH = 0; $(navigation).each(function (index) { var $this = $(this), totalH = 0; $this.children().each(function () { var $self = $(this); if (!($self.css('position') == 'absolute')) { totalH += $self.outerHeight(true); } }); if (maxH < totalH) { maxH = totalH } }); $(navigation).height(maxH); } // main menu function /*! * * Copyright (c) David Bushell | http://dbushell.com/ * */ (function (window, document, undefined) { var scrollW = (window.innerWidth - $(window).width()); // helper functions var trim = function (str) { return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, ''); }; var hasClass = function (el, cn) { return (' ' + el.className + ' ').indexOf(' ' + cn + ' ') !== -1; }; var addClass = function (el, cn) { if (!hasClass(el, cn)) { el.className = (el.className === '') ? cn : el.className + ' ' + cn; } }; var removeClass = function (el, cn) { el.className = trim((' ' + el.className + ' ').replace(' ' + cn + ' ', ' ')); }; var hasParent = function (el, id) { if (el) { do { if (el.id === id) { return true; } if (el.nodeType === 9) { break; } } while ((el = el.parentNode)); } return false; }; // normalize vendor prefixes var doc = document.documentElement; var transform_prop = window.Modernizr.prefixed('transform'), transition_prop = window.Modernizr.prefixed('transition'), transition_end = (function () { var props = { 'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'oTransitionEnd otransitionend', 'msTransition': 'MSTransitionEnd', 'transition': 'transitionend' }; return props.hasOwnProperty(transition_prop) ? props[transition_prop] : false; })(); window.App = (function () { var _init = false, app = {}; var inner = document.getElementById('inner-wrap'), widthW = document.body.clientWidth, nav_class = 'js-nav'; addClass(doc, 'js-ready'); if (widthW > (1499 - scrollWidth)) { nav_open = false; mobile_nav = false; document.getElementById('nav-open-btn-text').innerHTML="menu"; } else { nav_open = false; mobile_nav = true; }; app.init = function () { if (_init) { return; } _init = true; var closeNavEnd = function (e) { if (e && e.target === inner) { document.removeEventListener(transition_end, closeNavEnd, false); } nav_open = false; }; app.closeNav = function () { if (nav_open) { closeNavEnd(null); } removeClass(doc, nav_class); mobile_nav = false; document.getElementById('nav-open-btn-text').innerHTML="menu"; calculateInnerWrapWidth(); calculateWrapWidth(); }; app.openNav = function () { if (nav_open) { return; } addClass(doc, nav_class); document.getElementById('nav-open-btn-text').innerHTML="close"; nav_open = true; var widthW = document.body.clientWidth; if (widthW < (1499 - scrollWidth)) { mobile_nav = true; } calculateInnerWrapWidth(); calculateWrapWidth(); maxTileH = 0; calculateHeight(); $('.main-menu a:eq(0)').focus(); }; app.toggleNav = function (e) { if (nav_open && hasClass(doc, nav_class)) { app.closeNav(); } else { app.openNav(); } if (e) { e.preventDefault(); } }; // open nav with main "nav" button document.getElementById('nav-open-btn').addEventListener('click', app.toggleNav, false); // close nav with main "close" button //document.getElementById('nav-close-btn').addEventListener('click', app.toggleNav, false); // close nav by touching the partial off-screen content document.addEventListener('click', function (e) { if (nav_open && !hasParent(e.target, 'main-nav-mobile') && !hasClass(e.target, 'hamburger-icon') ) { //e.preventDefault(); //app.closeNav(); } }, true); //addClass(doc, 'js-ready'); }; return app; })(); if (window.addEventListener) { window.addEventListener('DOMContentLoaded', window.App.init, false); } window.onresize = function(){ var widthW = document.body.clientWidth; addClass(doc, 'js-ready'); if (widthW > (1499 - scrollWidth)) { if (mobile_nav) { nav_open = false; mobile_nav = true; //addClass(doc, 'js-nav'); document.getElementById('nav-open-btn-text').innerHTML="menu"; } } else { if (!mobile_nav) { nav_open = false; mobile_nav = true; //removeClass(doc, 'js-nav'); document.getElementById('nav-open-btn-text').innerHTML="menu"; } }; } })(window, window.document); })(jQuery);