-
Notifications
You must be signed in to change notification settings - Fork 1
/
kaka.js
47 lines (34 loc) · 1.28 KB
/
kaka.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Kaka - The Embeddable Cookie Library
// Kaka was created for a purpose, and one purpose only. To add simple cookie support for libraries that need it!
// It does this with a simple unrestricted license. So change the code, the name (please!), and use it however you like!!
// https://github.com/comfirm/Kaka.js
var Kaka = window.Kaka = {};
Kaka.get = function(name){
var cookies = {};
var decodeComponent = decodeURIComponent;
var data = (document.cookie || "").split("; ");
for(var i=0;i<data.length;++i){
var segments = data[i].split("=", 2);
if(segments.length == 2){
cookies[decodeComponent(segments[0])] = decodeComponent(segments[1]);
}
}
return (name === undefined ? cookies : (name in cookies ? cookies[name] : null));
};
Kaka.set = function(name, value, expires, path){
var variables = {};
var encodeComponent = encodeURIComponent;
variables[name] = value == undefined || value == null ? '' : value;
variables['path'] = path || '/';
if(expires && expires.toGMTString){
variables["expires"] = expires.toGMTString();
}
var cookie = "";
for(var key in variables){
cookie += (cookie != "" ? "; " : "") + encodeComponent(key) + "=" + encodeComponent[key];
}
document.cookie = cookie;
};
Kaka.remove = function(name){
Cookies.set(name, null, new Date(0));
};