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