First Local Commit - After Clean up.
Signed-off-by: Rick Hays <rhays@haysgang.com>
This commit is contained in:
53
public/assets/js/OLD/cookie-jar.js
Normal file
53
public/assets/js/OLD/cookie-jar.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* createCookie - Creates a cookie with Name->Value pair, and will stay active for x hours
|
||||
*
|
||||
* @date 2019-11-08
|
||||
* @author Rick Hays
|
||||
* @param name
|
||||
* @param value
|
||||
* @param hours
|
||||
*/
|
||||
function createCookie(name, value, hours)
|
||||
{
|
||||
let expires = "";
|
||||
if (hours)
|
||||
{
|
||||
let date = new Date();
|
||||
date.setTime(date.getTime()+(hours*60*60*1000));
|
||||
expires='' + date.toUTCString(); //.toGMTString();
|
||||
}
|
||||
document.cookie = name + '=' + value + '; expires=' + expires + "; path=/";
|
||||
}
|
||||
|
||||
/**
|
||||
* readCookie - reads the value of the name->value pair using the name, returns NULL if not found.
|
||||
*
|
||||
* @date 2019-11-08
|
||||
* @author Rick Hays
|
||||
* @param name
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function readCookie(name)
|
||||
{
|
||||
let nameEQ = name + "=";
|
||||
let ca = document.cookie.split(';');
|
||||
for(let i = 0; i < ca.length; i++)
|
||||
{
|
||||
let c = ca[i];
|
||||
while (c.charAt(0)==' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* eraseCookie - erases cookie with the name->vaule pair.
|
||||
*
|
||||
* @date 2019-11-08
|
||||
* @author Rick Hays
|
||||
* @param name
|
||||
*/
|
||||
function eraseCookie(name)
|
||||
{
|
||||
createCookie(name,"",-1);
|
||||
}
|
||||
Reference in New Issue
Block a user