Created
November 23, 2015 18:13
-
-
Save tantita/ad9115c2d49f40bf653c to your computer and use it in GitHub Desktop.
Object oriented JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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