-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·209 lines (182 loc) · 5.75 KB
/
script.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
var time_remaining = 0;
var selected_user = null;
var valid_image = /.*\.(png|svg|jpg|jpeg|bmp)$/i;
///////////////////////////////////////////////
// CALLBACK API. Called by the webkit greeeter
///////////////////////////////////////////////
// called when the greeter asks to show a login prompt for a user
function show_prompt(text) {
var password_container = document.querySelector("#password_container");
var password_entry = document.querySelector("#password_entry");
if (!isVisible(password_container)) {
var users = document.querySelectorAll(".user");
var user_node = document.querySelector("#"+selected_user);
var rect = user_node.getClientRects()[0];
var parentRect = user_node.parentElement.getClientRects()[0];
var center = parentRect.width/2;
var left = center - rect.width/2 - rect.left;
var i = 0;
if (left < 5 && left > -5) {
left = 0;
}
for (i = 0; i < users.length; i++) {
var node = users[i];
setVisible(node, node.id === selected_user);
node.style.left= left;
}
setVisible(password_container, true);
password_entry.placeholder= text.replace(":", "");
}
password_entry.value= "";
password_entry.focus();
}
// called when the greeter asks to show a message
function show_message(text) {
var message = document.querySelector("#message_content");
message.innerHTML= text;
if (text) {
document.querySelector("#message").classList.remove("hidden");
} else {
document.querySelector("#message").classList.add("hidden");
}
message.classList.remove("error");
}
// called when the greeter asks to show an error
function show_error(text) {
show_message(text);
var message = document.querySelector("#message_content");
message.classList.add("error");
}
// called when the greeter is finished the authentication request
function authentication_complete() {
if (lightdm.is_authenticated) {
lightdm.login(lightdm.authentication_user, lightdm.default_session);
} else {
show_error("<i class=\"fas fa-times\"></i>\n");
start_authentication(selected_user);
}
}
// called when the greeter wants us to perform a timed login
function timed_login(user) {
lightdm.login (lightdm.timed_login_user);
//setTimeout('throbber()', 1000);
}
//////////////////////////////
// Implementation
//////////////////////////////
function start_authentication(username) {
lightdm.cancel_timed_login();
selected_user = username;
lightdm.start_authentication(username);
}
function provide_secret() {
show_message("<i class=\"fas fa-check\"></i>");
entry = document.querySelector('#password_entry');
lightdm.provide_secret(entry.value);
}
function show_users() {
var users = document.querySelectorAll(".user");
var i = 0;
for (i= 0; i < users.length; i++) {
setVisible(users[i], true);
users[i].style.left = 0;
}
// setVisible(document.querySelector("#password_container"), false);
// selected_user = null;
}
function user_clicked(event) {
if (selected_user !== null) {
selected_user = null;
lightdm.cancel_authentication();
show_users();
} else {
selected_user = event.currentTarget.id;
start_authentication(event.currentTarget.id);
}
show_message("");
event.stopPropagation();
return false;
}
function setVisible(element, visible) {
console.log(element);
console.log(visible);
if (visible) {
element.classList.remove("hidden");
} else {
element.classList.add("hidden");
}
}
function isVisible(element) {
return !element.classList.contains("hidden");
}
function getDayOfWeek(date) {
var dayOfWeek = new Date(date).getDay();
return isNaN(dayOfWeek) ? null : ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek];
}
function update_time() {
var time = document.querySelector("#current_time");
var date = new Date();
var hh = date.getHours();
var mm = date.getMinutes();
var ss = date.getSeconds();
var dayofweek = getDayOfWeek(date);
var datea = date.getDate();
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDay();
if (hh < 10) { hh = "0"+hh; }
if (mm < 10) { mm = "0"+mm; }
if (ss < 10) { ss = "0"+ss; }
time.innerHTML = hh+":"+mm+":"+ss+" "+dayofweek+" "+day+"."+month+"."+year;
}
//////////////////////////////////
// Initialization
//////////////////////////////////
function initialize() {
show_message("");
initialize_users();
initialize_timer();
}
function on_image_error(e) {
e.currentTarget.src = "img/avatar.png";
}
function initialize_users() {
var template = document.querySelector("#user_template");
var parent = template.parentElement;
parent.removeChild(template);
for (i = 0; i < lightdm.users.length; i += 1) {
user = lightdm.users[i];
userNode = template.cloneNode(true);
var image = userNode.querySelectorAll(".user_image")[0];
var name = userNode.querySelectorAll(".user_name")[0];
name.innerHTML = user.display_name;
if (user.image) {
image.src = user.image;
image.onerror = on_image_error;
} else {
image.src = "img/avatar.png";
}
userNode.id = user.name;
// userNode.onclick = user_clicked;
parent.appendChild(userNode);
selected_user = user.name;
start_authentication(user.name);
show_message("");
// userNode.onclick();
}
setTimeout(show_users, 400);
}
function initialize_timer() {
update_time();
setInterval(update_time, 1000);
}
function add_action(id, name, image, clickhandler, template, parent) {
action_node = template.cloneNode(true);
action_node.id = "action_" + id;
img_node = action_node.querySelectorAll(".action_image")[0];
label_node = action_node.querySelectorAll(".action_label")[0];
label_node.innerHTML = name;
img_node.src = image;
action_node.onclick = clickhandler;
parent.appendChild(action_node);
}