1 |
1e2b2c27
|
Tomáš Šimandl
|
/**
|
2 |
|
|
* Class containing cookie utility functions.
|
3 |
|
|
* @constructor
|
4 |
|
|
*/
|
5 |
|
|
function Cookies() {
|
6 |
|
|
/**
|
7 |
|
|
* Gets the value of a cookie.
|
8 |
|
|
*
|
9 |
|
|
* @param {string} name Name of the cookie.
|
10 |
|
|
*/
|
11 |
|
|
this.get = function(name) {
|
12 |
|
|
var cookies = document.cookie.split('; ');
|
13 |
|
|
|
14 |
|
|
var cookie = cookies.find(function(cookie) {
|
15 |
|
|
return cookie.startsWith(name + '=');
|
16 |
|
|
});
|
17 |
|
|
|
18 |
|
|
if (typeof cookie === 'undefined') return null;
|
19 |
|
|
|
20 |
|
|
return cookie.split('=')[1];
|
21 |
|
|
};
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Sets a new cookie.
|
25 |
|
|
*
|
26 |
|
|
* @param {string} name Name of the cookie.
|
27 |
|
|
* @param {string} value Value of the cookie.
|
28 |
|
|
*/
|
29 |
|
|
this.set = function(name, value) {
|
30 |
|
|
var date = new Date();
|
31 |
|
|
|
32 |
|
|
document.cookie = name + "=" + value + "; path=/cocaex-compatibility";
|
33 |
|
|
};
|
34 |
|
|
}
|