1jQuery( function( $ ) { 2 'use strict'; 3 4 var countrySwitcherEl = $('.js-country-switcher'); 5 var countrySwitcherToggleEl = $('.js-country-switcher__toggle'); 6 var switchCountryBtnEl = $('.js-country-switcher__change-country'); 7 var currentCountryPopupEl = $('.js-country-switcher__current-country'); 8 var countrySelectionpPopupEl = $('.js-country-switcher__country-selection'); 9 var regionsList = $('.js-country-switcher__region'); 10 var countriesList = $('.js-country-switcher__country'); 11 var closeOverlayEl = $('.js-country-switcher__close'); 12 13 var ACTIVE_CLASS = 'is-active'; 14 var HIDDEN_CLASS = 'is-hidden'; 15 16 if( 17 countrySwitcherEl.length && 18 countrySwitcherToggleEl.length 19 ) { 20 // load initial state 21 initCountrySwitcher(); 22 23 // bind UI events 24 countrySwitcherToggleEl.on('click', openOverlay); 25 closeOverlayEl.on('click', closeOverlay); 26 switchCountryBtnEl.on('click', openCountrySelection); 27 regionsList.on('click', changeRegion); 28 $(document.body).on('sponsorSaved', decorateCountryLinks); 29 30 31 // 32 // Implementation 33 // 34 function initCountrySwitcher() { 35 var firstRegionInList = regionsList.first(); 36 37 firstRegionInList.addClass('is-active'); 38 showCountriesByRegion(firstRegionInList.data('region')); 39 } 40 41 function openCountrySelection() { 42 currentCountryPopupEl.addClass(HIDDEN_CLASS); 43 countrySelectionpPopupEl.removeClass(HIDDEN_CLASS); 44 } 45 46 function changeRegion() { 47 var clickedRegion = $(this); 48 var clickedRegionName = clickedRegion.data('region'); 49 50 if(clickedRegionName) { 51 regionsList.filter('.' + ACTIVE_CLASS).removeClass(ACTIVE_CLASS); 52 clickedRegion.addClass(ACTIVE_CLASS); 53 54 showCountriesByRegion(clickedRegionName); 55 } 56 } 57 58 function showCountriesByRegion(region) { 59 countriesList.addClass(HIDDEN_CLASS); 60 countriesList.filter('[data-region="' + region + '"]').removeClass(HIDDEN_CLASS); 61 } 62 63 function resetCountrySwitcher() { 64 countrySelectionpPopupEl.addClass(HIDDEN_CLASS); 65 currentCountryPopupEl.removeClass(HIDDEN_CLASS); 66 regionsList.removeClass(ACTIVE_CLASS); 67 68 initCountrySwitcher(); 69 } 70 71 function openOverlay() { 72 countrySwitcherEl.removeClass(HIDDEN_CLASS); 73 } 74 75 function closeOverlay() { 76 resetCountrySwitcher(); 77 78 countrySwitcherEl.addClass(HIDDEN_CLASS); 79 } 80 81 /** 82 * decorates all country links with the saved sponsor name 83 * on next page load it is taken from session 84 * @param e 85 * @param data 86 */ 87 function decorateCountryLinks(e, data) { 88 if(data.sponsorName) { 89 $.each(countriesList, function() { 90 var countryEl = $(this); 91 var countryUrl = countryEl.attr('href'); 92 93 if(countryUrl && countryUrl.indexOf('partnername') === -1) { 94 countryEl.attr('href', countryUrl + '?partnername=' + data.sponsorName); 95 } 96 }) 97 } 98 } 99 } 100});
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.