Skip to content

Instantly share code, notes, and snippets.

@tantita
Created November 23, 2015 18:13
Show Gist options
  • Select an option

  • Save tantita/ad9115c2d49f40bf653c to your computer and use it in GitHub Desktop.

Select an option

Save tantita/ad9115c2d49f40bf653c to your computer and use it in GitHub Desktop.
Object oriented JS
var Cookies = {
init: function () {
var allCookies = document.cookie.split('; ');
for (var i=0;i<allCookies.length;i++) {
var cookiePair = allCookies[i].split('=');
this[cookiePair[0]] = cookiePair[1];
}
},
create: function (name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
this[name] = value;
},
erase: function (name) {
this.create(name,'',-1);
this[name] = undefined;
}
};
Cookies.init();
Cookies.create('hide_livechat', 'yes', '');
if(Cookies['cart_items'] != undefined) {
cart_items = Cookies['cart_items'];
}
if(Cookies['custname'] != undefined) {
custname = Cookies['custname'];
custname = decodeURI(custname.replace(/\+/g, "%20"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment