Last active
December 10, 2015 19:48
Revisions
-
wthit56 revised this gist
Jan 8, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ if (!window.BakeCookies) { window.BakeCookies = { set: (function () { @@ -62,4 +61,4 @@ console.log("cookie: ", document.cookie); console.log("1 day expiry: ", BakeCookies.get("1 day expiry")); console.log("with date: ", BakeCookies.get("with date")); console.log("session: ", BakeCookies.get("session")); console.log("expired: ", BakeCookies.get("expired")); -
wthit56 revised this gist
Jan 8, 2013 . 2 changed files with 65 additions and 25 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ if (!window.BakeCookies) { window.BakeCookies = { set: (function () { var days; return function BakeCookies_set(name, value, expires) { if ((expires != null) && !(expires instanceof Date)) { switch (typeof (expires)) { case "number": days = expires; expires = new Date(); expires.setDate(expires.getDate() + days); break; case "string": expires = new Date(expires); break; default: expires = null; } } document.cookie = ( escape(name) + "=" + escape(value) + ( expires == null ? "" : "; expires=" + expires.toUTCString() ) ); }; })(), get: (function () { var find = /(?:^|;|\s){name}=([\W\w]*?)(?:;|\s|$)/.source, found; return function BakeCookies_get(name) { found = new RegExp(find.replace("{name}", escape(name))).exec(document.cookie); if (found) { return unescape(found[1]); } else { return null; } }; })() }; } // tests var future_expiry = new Date(); future_expiry.setYear(3000); // set BakeCookies.set('1 day expiry', 'set', 1); BakeCookies.set('with date', 'set2', future_expiry); BakeCookies.set('session', '3set'); BakeCookies.set('expired', 'value', new Date(0)); console.log("cookie: ", document.cookie); // get console.log("1 day expiry: ", BakeCookies.get("1 day expiry")); console.log("with date: ", BakeCookies.get("with date")); console.log("session: ", BakeCookies.get("session")); console.log("expired: ", BakeCookies.get("expired")); -
Chris Whitney renamed this gist
Dec 24, 2012 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ function bake_cookie(c_name,value,exdays){ exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; }; this.get = function(c_name){ var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++){ @@ -15,5 +15,11 @@ function bake_cookie(c_name,value,exdays){ return unescape(y); } } }; } // to create the object var bakecookie = new bake_cookie(); // set cookie bakecookie.set('test','set',1); // get cookie alert(bakecookie.get('test')); -
Chris Whitney created this gist
Dec 24, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ function bake_cookie(c_name,value,exdays){ this.set = function(c_name,value,exdays){ var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } this.get = function(c_name){ var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++){ x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name){ return unescape(y); } } } }