1(function () { 2 let horCountrySwitcher = { 3 cookieNameCountry: 'horcountryswitch_country', 4 cookieNameDoNotShowAgain: 'horcountryswitch_nonotshowagain', 5 ttlCookieDoNotShowAgain: 30, 6 alternativeLangs: [], 7 pages: [], 8 currentLanguage: '', 9 initialized: false, 10 endpointCountryDetection: 'https://static.horiba.com/file'+'admin/countrycheck.php', 11 collectAlternatives() { 12 let alternativeLangs = []; 13 jQuery('link[rel="alternate"]').each(function () { 14 let hreflang = jQuery(this).attr('hreflang'); 15 let chunks = hreflang.split(/-/); 16 if (Array.isArray(chunks) && 2 === chunks.length && 2 === chunks[1].length) { 17 horCountrySwitcher.alternativeLangs.push(chunks[1].toLowerCase()); 18 horCountrySwitcher.pages.push({country: chunks[1].toLowerCase(), url: jQuery(this).attr('href')}); 19 } 20 else if (Array.isArray(chunks) && 1 === chunks.length && 2 === chunks[0].length) { 21 horCountrySwitcher.alternativeLangs.push(chunks[0].toLowerCase()); 22 horCountrySwitcher.pages.push({country: chunks[0].toLowerCase(), url: jQuery(this).attr('href')}); 23 } 24 }); 25 }, 26 getCurrentLanguageFromHTML() { 27 let lang = jQuery('html').attr('lang'); 28 let chunks = lang.split(/-/); 29 if (Array.isArray(chunks) && 2 === chunks.length && 2 === chunks[1].length) { 30 horCountrySwitcher.currentLanguage = chunks[1].toLowerCase(); 31 } else { 32 // we have a two digit code 33 horCountrySwitcher.currentLanguage = chunks[0].toLowerCase(); 34 } 35 }, 36 alternativeAvailable(probe) { 37 probe = probe.toLowerCase(); 38 return -1 !== horCountrySwitcher.alternativeLangs.indexOf(probe) ? true : false; 39 }, 40 getCurrentCountryByRemoteCall() { 41 jQuery.getJSON(horCountrySwitcher.endpointCountryDetection, function () { 42 }) 43 .done(function (data) { 44 45 if ('object' === typeof data && data.country) { 46 let country = data.country.toLowerCase(); 47 horCountrySwitcher.setCookie(horCountrySwitcher.cookieNameCountry, country); 48 horCountrySwitcher.checkIfReady(country); 49 } 50 }); 51 }, 52 getCookie(name) { 53 var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)'); 54 return v ? v[2] : null; 55 }, 56 setCookie(name, value, days) { 57 var d = new Date; 58 d.setTime(d.getTime() + 24 * 60 * 60 * 1000 * days); 59 document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString(); 60 }, 61 translations: {}, 62 getTextWithTranslation(key, country) { 63 let en = horCountrySwitcher.getText(key, 'en'); 64 let translation = horCountrySwitcher.getText(key, country); 65 66 // if requested language is en we need no translation appended 67 if ('en' === country) { 68 return translation; 69 } 70 return null === translation ? en : en + ' / ' + translation; 71 }, 72 getTextWithFallback(key, country) { 73 let translation = horCountrySwitcher.getText(key, country); 74 75 return null !== translation ? translation : horCountrySwitcher.getText(key, 'en'); 76 }, 77 getText(key, country) { 78 let translation = (country in horCountrySwitcher.translations) && (key in horCountrySwitcher.translations[country]) 79 ? horCountrySwitcher.translations[country][key] : null; 80 81 return translation; 82 }, 83 84 getTextTargetCountry(country) { 85 return horCountrySwitcher.translations.global[country]; 86 }, 87 88 showBanner(country) { 89 90 let textBanner = horCountrySwitcher.getTextWithFallback('target_lang_text', country) 91 let textButtonNext = horCountrySwitcher.getTextWithFallback('btn_continue', country) 92 let textCountry = horCountrySwitcher.getTextTargetCountry(country) 93 94 let bannerTemplate = `<div id="language-selection-hint" class="position-relative"> <div class="container py-2"> <div class="row"> <div class="col-12 col-md-5 mb-2 mb-md-0 first-col"> <div class="country-switcher-text">${textBanner}</div> </div> <div class="col-12 col-md-7"> <div class="country-switcher-country"><i class="fa-solid fa-check"></i>${textCountry}</div> <button type="button" class="btn btn-primary btn-continue country-switcher-btn-continue">${textButtonNext}</button> <button type="button" class="country-switcher-btn-close close"><i aria-hidden="true" class="fa-light fa-xmark"></i></button> </div> </div> </div></div>`; 95 let langBanner = jQuery(bannerTemplate); 96 langBanner.find('.close').bind('click', function() { 97 langBanner.hide(); 98 horCountrySwitcher.setCookie(horCountrySwitcher.cookieNameDoNotShowAgain, 1, horCountrySwitcher.ttlCookieDoNotShowAgain); 99 jQuery('.hor-spacer-content').removeClass('banner-active'); 100 }); 101 langBanner.find('.btn-continue').bind('click', function() { 102 // a translated page is available 103 if (horCountrySwitcher.alternativeAvailable(country)) { 104 let newUrl = horCountrySwitcher.getPageUrlForCountry(country); 105 if (null !== newUrl) { 106 location.href = newUrl; 107 } 108 } 109 else { 110 // no translation for the current page available, use the front page 111 countryToUse = 'gb' === country ? 'uk' : country; 112 113 // watch out! gb (hreflang) is uk (in metanavigation 114 if ('object' === typeof hor && 'object' === typeof hor.metanavigation && 'object' === typeof hor.metanavigation.model && 'object' === typeof hor.metanavigation.model.location && 'object' === typeof hor.metanavigation.model.location.assignment && 115 countryToUse in hor.metanavigation.model.location.assignment) { 116 location.href = hor.metanavigation.model.location.assignment[countryToUse].fallback; 117 } 118 } 119 }); 120 121 langBanner.prependTo(jQuery('header:first')); 122 jQuery('.hor-spacer-content').addClass('banner-active'); 123 jQuery('body').addClass('horcountryswitcher-inactive'); 124 }, 125 getPageUrlForCountry(country) { 126 for (let i = 0; i < horCountrySwitcher.pages.length; i++) { 127 if (horCountrySwitcher.pages[i].country === country) { 128 return (horCountrySwitcher.pages[i].url); 129 } 130 } 131 132 return null; 133 }, 134 checkIfReady(country) { 135 // check if the current page language is the same as in the cookie 136 if (horCountrySwitcher.currentLanguage === country) { 137 return; 138 } 139 140 // check if there's an alternative language for the current page 141 if (horCountrySwitcher.alternativeAvailable(country)) { 142 horCountrySwitcher.showBanner(country); 143 } else { 144 } 145 146 }, 147 init(translations) { 148 horCountrySwitcher.translations = translations; 149 horCountrySwitcher.collectAlternatives(); 150 horCountrySwitcher.getCurrentLanguageFromHTML(); 151 152 let doNotshowBannerAgain = horCountrySwitcher.getCookie(horCountrySwitcher.cookieNameDoNotShowAgain); 153 if (1 == doNotshowBannerAgain) { 154 return; 155 } 156 157 let country = horCountrySwitcher.getCookie(horCountrySwitcher.cookieNameCountry); 158 // cookie available? Proceed. 159 if (null !== country) { 160 this.checkIfReady(country); 161 } else { 162 // get result from remote file first 163 horCountrySwitcher.getCurrentCountryByRemoteCall(); 164 } 165 166 } 167 }; 168 169 window.horCountrySwitcher = horCountrySwitcher; 170})(); 171
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.