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('.')[2] !== 'undefined') { countryCodeDomain = document.domain.split('.')[1]+'.'+document.domain.split('.')[2]; } 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