1
|
/**
|
2
|
* Created by stefanos on 2/3/2017.
|
3
|
*/
|
4
|
|
5
|
export function getCookie(name: string) : string {
|
6
|
let ca: string[] = document.cookie.split(';');
|
7
|
let caLen: number = ca.length;
|
8
|
let cookieName = `${name}=`;
|
9
|
let c: string;
|
10
|
/*console.log(`document.cookie is: ${document.cookie.toString()}`);
|
11
|
console.log(`ca is: ${JSON.stringify(ca)}`);*/
|
12
|
for (let i: number = 0; i < caLen; i += 1) {
|
13
|
c = ca[i].replace(/^\s+/g, '');
|
14
|
if (c.indexOf(cookieName) == 0) {
|
15
|
return c.substring(cookieName.length, c.length);
|
16
|
}
|
17
|
}
|
18
|
|
19
|
return null;
|
20
|
}
|
21
|
|
22
|
export function deleteCookie(name) {
|
23
|
setCookie(name, '', -1);
|
24
|
console.log(`after delete: document.cookie is: ${document.cookie.toString()}`);
|
25
|
}
|
26
|
|
27
|
/* defaulr path used to be '' */
|
28
|
function setCookie(name: string, value: string, expireDays: number, path: string = '/') {
|
29
|
let d:Date = new Date();
|
30
|
d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
|
31
|
let expires:string = `expires=${d.toUTCString()}`;
|
32
|
/*let cpath:string = path ? `; path=${path}` : '';*/
|
33
|
/*document.cookie = `${name}=${value}; ${expires}${cpath}`;*/
|
34
|
|
35
|
/* new code from Argyro */
|
36
|
let domain = "";
|
37
|
if (document.domain.indexOf(".di.uoa.gr")!= -1) { // for development
|
38
|
domain = ".athenarc.gr";
|
39
|
} else if(document.domain.indexOf(".openaire.eu") != -1) {
|
40
|
domain = ".openaire.eu";
|
41
|
}
|
42
|
document.cookie = name+'='+value+'; path='+path+'; domain='+domain+';';
|
43
|
}
|