javascript class example
var countryCookieRedirect = {
internationalUrl: '',
intlCookieName: '',
visitorCountry: '',
cookie: Cookies.get('ct_location'),
urlRedirect: '',
cookieCountyCode: '',
checkCookie: function () {
if (countryCookieRedirect.cookie) {
if (countryCookieRedirect.cookie === countryCookieRedirect.intlCookieName) {
document.location.href = countryCookieRedirect.internationalUrl;
} else {
document.location = document.location.protocol + '//' + document.location.host + '/' + countryCookieRedirect.cookie + '/';
}
}
},
setCookieVisitorLocation: function(){
Cookies.set(
'ct_location',
countryCookieRedirect.cookieCountyCode,
{expires: 3653, path: '/'}
);
},
checkAndSetVisitorCookie: function(){
if ( ! countryCookieRedirect.cookie || countryCookieRedirect.cookie === 'undefined') {
countryCookieRedirect.setCookieVisitorLocation(countryCookieRedirect.cookie);
if (countryCookieRedirect.visitorCountry === countryCookieRedirect.intlCookieName) {
document.location.href = countryCookieRedirect.internationalUrl;
} else {
document.location = countryCookieRedirect.urlRedirect;
}
}
}
};