forked from verdnatura/hedera-web
72 lines
1.0 KiB
JavaScript
72 lines
1.0 KiB
JavaScript
|
/**
|
||
|
* Brownser cookie handler.
|
||
|
**/
|
||
|
Vn.Cookie =
|
||
|
{
|
||
|
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)
|
||
|
{
|
||
|
var value = Cookie.get (key);
|
||
|
|
||
|
if (value != null)
|
||
|
return parseFloat (value);
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
,check: function (key)
|
||
|
{
|
||
|
return this.get (key) != null;
|
||
|
}
|
||
|
};
|
||
|
|