Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class CookieLocale {
- /**
- * @param {HTMLelement} container
- */
- constructor(container) {
- this.container = container;
- this.cookieId = 'cookie-origin';
- this.countries = [...this.container.getElementsByClassName('js-country')];
- this.countries.forEach((country) => {
- country.addEventListener('click', this.handleClick);
- });
- }
- setCookie = (countryLocale) => {
- const cookieObject = window.globals.cookies[this.cookieId];
- const cookieExpiration = cookieObject.expiration;
- const cookieName = cookieObject.name;
- const dayInMs = 86400;
- const expiration = dayInMs * cookieExpiration;
- document.cookie = `${cookieName}=${countryLocale} ; max-age=${expiration}; path=/`;
- };
- handleClick = (event) => {
- event.preventDefault();
- if (event.currentTarget.dataset.locale !== undefined) {
- this.countryLocale = event.currentTarget.dataset.locale;
- this.setCookie(this.countryLocale);
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement