forked from MicrosoftDX/Vorlonjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vorlon.production.ts
65 lines (55 loc) · 1.83 KB
/
vorlon.production.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module VORLON {
export class Production{
public isActivated : boolean;
constructor(public vorlonServerUrl: string, public vorlonSessionId : string, public useLocalStorage?: boolean){
var storage = useLocalStorage ? localStorage : sessionStorage;
var mustActivate = storage["vorlonActivation"] === "true";
if (this.vorlonServerUrl && this.vorlonServerUrl[this.vorlonServerUrl.length-1] !== '/'){
this.vorlonServerUrl = this.vorlonServerUrl + "/";
}
if (mustActivate){
this.addVorlonScript();
}
}
addVorlonScript(){
var storage = this.useLocalStorage ? localStorage : sessionStorage;
storage["vorlonActivation"] = "true";
this.isActivated = true;
var scriptElt = <HTMLScriptElement>document.createElement("SCRIPT");
scriptElt.src = this.vorlonServerUrl + "vorlon.js" + (this.vorlonSessionId ? "/" + this.vorlonSessionId : "");
document.head.insertBefore(scriptElt, document.head.firstChild);
}
setIdentity(identity){
var storage = this.useLocalStorage ? localStorage : sessionStorage;
storage["vorlonClientIdentity"] = identity;
var v = <any>VORLON;
if (v && v.Core){
v.Core.sendHelo();
}
}
getIdentity(){
var storage = this.useLocalStorage ? localStorage : sessionStorage;
return storage["vorlonClientIdentity"];
}
activate(reload : boolean){
if (this.isActivated)
return;
if (reload){
var storage = this.useLocalStorage ? localStorage : sessionStorage;
storage["vorlonActivation"] = "true";
this.isActivated = true;
window.location.reload();
}else{
this.addVorlonScript();
}
}
deactivate(reload : boolean){
var storage = this.useLocalStorage ? localStorage : sessionStorage;
storage["vorlonActivation"] = "false";
this.isActivated = false;
if (reload){
window.location.reload();
}
}
}
}