forked from Rotonde/rotonde-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotonde.js
135 lines (114 loc) · 3.23 KB
/
rotonde.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function Rotonde(client_url)
{
this.client_url = client_url;
this.client_version = "0.2.8";
// SETUP
this.requirements = {style:["reset","fonts","main"],script:["util","home","portal","feed","entry","operator","oembed","status"]};
this.includes = {script:[]};
this.is_owner = false;
this.install = function()
{
for(id in this.requirements.script){
var name = this.requirements.script[id];
this.install_script(name);
}
for(id in this.requirements.style){
var name = this.requirements.style[id];
this.install_style(name);
}
this.install_style("custom", true);
}
this.install_style = function(name, is_user_side)
{
var href = "links/"+name+'.css';
if(!is_user_side) href = this.client_url+href;
var s = document.createElement('link');
s.rel = 'stylesheet';
s.type = 'text/css';
s.href = href;
document.getElementsByTagName('head')[0].appendChild(s);
}
this.install_script = function(name)
{
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = this.client_url+"scripts/"+name+'.js';
document.getElementsByTagName('head')[0].appendChild(s);
}
this.confirm = function(type,name)
{
console.log("Included:",type,name)
this.includes[type].push(name);
this.verify();
}
this.verify = function()
{
var remaining = [];
for(id in this.requirements.script){
var name = this.requirements.script[id];
if(this.includes.script.indexOf(name) < 0){ remaining.push(name); }
}
if(remaining.length == 0){
this.start();
}
}
// START
this.el = document.createElement('div');
this.el.className = "rotonde";
this.home = null;
this.portal = null;
this.operator = null;
this.status = null;
this.start = function()
{
console.info("Start")
document.body.appendChild(this.el);
document.addEventListener('mousedown',r.mouse_down, false);
document.addEventListener('keydown',r.key_down, false);
this.operator = new Operator();
this.operator.install(this.el);
this.status = new Status();
this.status.install(this.el);
this.home = new Home(); this.home.setup();
}
this.mouse_down = function(e)
{
if (e.button != 0) { return; } // We only care about the main mouse button.
if(!e.target.getAttribute("data-operation")){ return; }
e.preventDefault();
r.operator.inject(e.target.getAttribute("data-operation"));
if(!e.target.getAttribute("data-validate")){ return; }
r.operator.validate();
}
this.key_down = function(e)
{
if (e.which === 27) { // ESC
r.home.feed.bigpicture_hide();
} else if (e.which === 116) { // F5
r.operator.commands.portals_refresh();
r.home.update();
r.home.feed.refresh("hit F5");
e.preventDefault();
}
}
this.reset = function()
{
this.reset_with_name();
}
this.reset_with_name = async function()
{
this.home.portal.json = {
name: name,
desc: "new_desc",
port: [],
feed: [],
site: "",
// Deprecated but required to keep old versions working as long as possible.
dat: ""
};
this.home.save();
r.home.feed.refresh("reset_with_name");
}
}
// Make this accessible for jest
window.Rotonde = Rotonde;