-
Notifications
You must be signed in to change notification settings - Fork 0
/
crumb.js
37 lines (37 loc) · 1.08 KB
/
crumb.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
var Crumb = {
get: function(name) {
var cookies = document.cookie.split(';')
var n, v, i, l;
for (i = 0, l = cookies.length; i < l; i++) {
n = $.trim(cookies[i].substr(0, cookies[i].indexOf('=')));
v = cookies[i].substr(cookies[i]. indexOf('=') + 1);
if (n === name) {
return decodeURIComponent(v);
}
}
return '';
},
set: function(name, val, opts) {
var options = opts || {};
var value = val || '';
var d;
if (!value) {
options.expires = -365;
} else {
value = encodeURIComponent(value);
}
if (options.expires) {
d = new Date();
d.setDate(d.getDate() + options.expires);
value += '; expires=' + d.toUTCString();
}
if (options.domain) {
value += '; domain=' + options.domain;
}
if (options.path) {
value += '; path=' + options.path;
}
document.cookie = name + '=' + value;
return true;
}
};