class MDFooterSelectorLocalizationForm extends HTMLElement { constructor() { super(); this.elements = { selectorCountry: this.querySelector("#md-footer-selector__country"), selectorLanguage: this.querySelector("#md-footer-selector__language") }; this.elements.selectorCountry.addEventListener('change', this.onItemChange.bind(this)); this.elements.selectorLanguage.addEventListener('change', this.onItemChange.bind(this)); } onItemChange() { const form = this.querySelector('form'); let countrySelector = document.getElementById('md-footer-selector__country'); let countryCode = countrySelector[countrySelector.selectedIndex].dataset.country; let countryCodeDomain = document.domain; if (typeof document.domain.split('.')[3] !== 'undefined') { countryCodeDomain = document.domain.split('.')[2]+'.'+document.domain.split('.')[3]; } else if (typeof document.domain.split('.')[2] !== 'undefined') { countryCodeDomain = document.domain.split('.')[1]+'.'+document.domain.split('.')[2]; } let mdCountryRedirect = ''; let formInputReturnTo = document.querySelector("#md-footer-selector__form__id input[name='return_to']"); if (formInputReturnTo.value.includes('?')) { mdCountryRedirect = '&mdApp_countryCodeDomain=' + countryCode; } else { mdCountryRedirect = '?mdApp_countryCodeDomain=' + countryCode; } formInputReturnTo.value = formInputReturnTo.value + mdCountryRedirect; document.cookie = `mdApp_countryCodeDomain=${countryCode}; domain=${countryCodeDomain}; path=/; max-age=${60 * 60 * 24 * 60};`; if (form) { form.submit(); } } } customElements.define('md-footer-selector__form', MDFooterSelectorLocalizationForm);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter