2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* Brownser cookie handler.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports =
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2023-10-09 19:01:11 +00:00
|
|
|
set: function(key, value, days) {
|
2015-01-23 13:09:30 +00:00
|
|
|
var strCookie = key + '=' + value + ';';
|
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
if (days != undefined) {
|
|
|
|
var date = Date.vnNew();
|
|
|
|
date.setTime(date.getTime() + days * 86400000);
|
|
|
|
strCookie += 'expires=' + date.toGMTString();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
document.cookie = strCookie;
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
,unset: function(key) {
|
|
|
|
this.set(key, '', -1);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
,get: function(key) {
|
|
|
|
var cookie = new String(document.cookie);
|
|
|
|
var start = cookie.indexOf(key + '=');
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
if (start != -1) {
|
2015-01-23 13:09:30 +00:00
|
|
|
var end;
|
|
|
|
|
|
|
|
start += key.length + 1;
|
2023-10-09 19:01:11 +00:00
|
|
|
end = cookie.indexOf(';', start);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (end > 0)
|
2023-10-09 19:01:11 +00:00
|
|
|
return cookie.substring(start, end);
|
2015-01-23 13:09:30 +00:00
|
|
|
else
|
2023-10-09 19:01:11 +00:00
|
|
|
return cookie.substring(start);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
,getInt: function(key) {
|
|
|
|
var value = this.get(key);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (value != null)
|
2023-10-09 19:01:11 +00:00
|
|
|
return parseInt(value);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
,getFloat: function(key) {
|
|
|
|
var value = this.get(key);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (value != null)
|
2023-10-09 19:01:11 +00:00
|
|
|
return parseFloat(value);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
,check: function(key) {
|
|
|
|
return this.get(key) != null;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|