2016-01-12 15:08:37 -05:00
|
|
|
export default class Cookie {
|
|
|
|
// Thanks to http://www.quirksmode.org/js/cookies.html
|
|
|
|
static set (key, value) {
|
|
|
|
var year = new Date();
|
|
|
|
year.setTime(year.getTime() + (365 * 24 * 60 * 60 * 1000));
|
|
|
|
var expires = '; expires=' + year.toGMTString();
|
|
|
|
document.cookie = key + '=' + value + expires + '; path=/';
|
|
|
|
}
|
2016-01-08 14:31:04 -05:00
|
|
|
|
2016-01-12 15:08:37 -05:00
|
|
|
static get (key) {
|
|
|
|
key += '=';
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
|
|
var c = cookies[i];
|
|
|
|
while (c.charAt(0) == ' ') {
|
|
|
|
c = c.substring(1, c.length);
|
|
|
|
}
|
|
|
|
if (c.indexOf(key) == 0) {
|
|
|
|
return c.substring(key.length, c.length);
|
|
|
|
}
|
2016-01-08 14:31:04 -05:00
|
|
|
}
|
2016-01-12 15:08:37 -05:00
|
|
|
return null;
|
2016-01-08 14:31:04 -05:00
|
|
|
}
|
2016-01-12 15:08:37 -05:00
|
|
|
}
|