-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html.old
364 lines (310 loc) · 12.9 KB
/
index.html.old
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE>
<html>
<head>
<title>Hack Developers Italia</title>
<!-- This page can be configured by editing the self.config.json file -->
<link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet">
<style>
* { font-family: 'Titillium Web', sans-serif; color: white;}
html, body {margin:0; padding:0; width: 100%; height:100%;}
body { background-color: black;}
ul {list-style-type: none; display:inline-block; vertical-align: top; margin:0; padding:0; }
li {display: block;}
#container { background-image:url('background.jpg'); background-size: 100% 100%; background-position: center center; background-repeat: no-repeat; height:100%; width:100%; margin:auto; position:relative; }
@keyframes changing {
0% {transform: translate(0, 0);}
40% {transform: translate(0, -2vh); opacity: 0;}
60% {transform: translate(0, 2vh); opacity: 0;}
100% {transform: translate(0, 0); opacity: 1;}
}
#past-session .changing, #current-session .changing, #upcoming-sessions .changing { animation-name: changing; animation-duration: 1s; position:relative; animation-timing-function: ease-in-out;}
#past-session .changing {animation-delay: 0s;}
#current-session .changing {animation-delay: 0.2s;}
#upcoming-sessions .changing {animation-delay: 0.4s;}
#past-session {position:absolute; top:17%; height:9%; width: 100%;}
#current-session {position:absolute; top:31%; height:30%; width: 100%;}
#no-current-session {position:absolute; top:42%; height:10%; width: 100%;}
#upcoming-sessions {position:absolute; top:65%; height:17%; width: 100%;}
.session-timeframe {color: white; font-size: 4vh; text-transform: uppercase; display:inline-block; margin-right:4vh; padding-right:4vh; border-right: 0.4vh solid #eb6468; height:100%; float:left; padding-left: 30px; width: 22%; text-align:right;}
#no-current-session {font-size: 4vh; text-align:center; font-style: italic; color: rgba(255, 255, 255, 0.7)}
#past-session .session-timeframe, #past-session .session-time, #upcoming-sessions .session-timeframe, #upcoming-sessions .session-time {font-size:3vh; color: rgba(255, 255, 255, 0.7)}
.attendees-indicator {background-color: #f1751f; display: inline-block;}
.mentors-indicator {background-color: #8c36d7; display: inline-block;}
.session-time {margin-right:2vh; line-height:4vh}
.sessions>li {margin-bottom:10px;}
.audience-initial { width: 3.2vh; height:3.2vh; display: inline-block; margin-top:0.4vh; margin-right:1.6vh; text-align:center; font-size: 2vh; opacity: 0.7; vertical-align: top;}
.track-title { font-size: 4.5vh; line-height:4vh; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; display:inline-block; vertical-align: top;}
#past-session .track-title, #upcoming-sessions .track-title { font-size: 3vh; color: rgba(255, 255, 255, 0.7); }
#current-session .track-title { vertical-align:middle; display:inline-block; line-height: 7vh; }
.audience {font-size: 1.9vh; line-height: 3.6vh; width: 13.2vh; height:3.5vh; text-transform: uppercase; text-align:center; vertical-align: middle; margin-right: 1.6vh;}
#current-session .session-time {font-size: 5vh; margin-left:1vh;}
.session-time-at {font-size: 4vh;}
</style>
</head>
<body>
<div id="container" data-bind="if: loaded">
<!-- Past session -->
<div id="past-session" data-bind="if: pastSession">
<label class="session-timeframe" data-bind="text: labels.pastSessionTime"></label>
<div data-bind="with: pastSession, css: {changing: changingSession}">
<span class="session-time" data-bind="text: $root.formatTime(when)"></span>
<ul data-bind="foreach: tracks">
<li>
<span class="audience-initial" data-bind="text: $root.formatAudienceInitial(who), css: {'attendees-indicator': who == 'attendees', 'mentors-indicator': who == 'mentors'}"></span>
<span class="track-title" data-bind="text: what"></span>
</li>
</ul>
</div>
</div>
<!-- Current session -->
<div id="current-session" data-bind="if: currentSession">
<label class="session-timeframe" data-bind="text: sessionStartingIn"></label>
<div data-bind="with: currentSession, css: {changing: changingSession}">
<div>
<span class="session-time-at" data-bind="text: $root.labels.at"></span>
<strong class="session-time" data-bind="text: $root.formatTime(when)"></strong>
</div>
<ul data-bind="foreach: tracks">
<li>
<span class="audience" data-bind="text: $root.formatAudience(who), css: {'attendees-indicator': who == 'attendees', 'mentors-indicator': who == 'mentors'}"></span> <span class="track-title" data-bind="text: what"></span>
</li>
</ul>
</div>
</div>
<div id="no-current-session" data-bind="if: !currentSession()">
<!-- ko text: labels.noSessions --><!-- /ko -->
</div>
<!-- Upcoming sessions -->
<div id="upcoming-sessions" data-bind="if: upcomingSessions().length > 0">
<label class="session-timeframe" data-bind="text: labels.upcomingSessionsTime"></label>
<ul class="sessions" data-bind="css: {changing: changingSession}, foreach: upcomingSessions">
<li>
<span class="session-time" data-bind="text: $root.formatTime(when)"></span>
<ul data-bind="foreach: tracks">
<li>
<span class="audience-initial" data-bind="text: $root.formatAudienceInitial(who), css: {'attendees-indicator': who == 'attendees', 'mentors-indicator': who == 'mentors'}"></span>
<span class="track-title" data-bind="text: what"></span>
</li>
</ul>
</li>
</ul>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<script>
function AgendaViewModel() {
var self = this;
self.pastSession = ko.observable(null);
self.currentSession = ko.observable(null);
self.upcomingSessions = ko.observableArray([]);
self.changingSession = ko.observable(false);
self.sessionStartingIn = ko.observable("");
self.labels = null;
self.config = null;
self.updatedConfig = null;
self.loaded = ko.observable(false);
function updateConfiguration() {
getJson("config.json?v=" + Math.random(), function(error, data) {
if (!error) {
var needsUpdate = self.updatedConfig == null;
self.updatedConfig = data;
if (needsUpdate) {
updateSessions();
}
} else {
console.error("Couldn't update configuration, will try again in a few minutes...");
}
})
}
function updateSessions() {
if (!self.config && !self.updatedConfig)
return;
if (self.config != self.updatedConfig) {
self.config = self.updatedConfig.config;
self.config.sessions.forEach(function(item) { item.when = new Date(item.when); });
//self.config.sessions.sort(function(item1, item2) { return item1.when.getTime() > item2.when.getTime();});
var language = /lang=(en|it)/.exec(window.location.search);
if (language) {
language = language[1];
} else {
language = "it";
}
self.labels = self.updatedConfig.labels[language];
if (!self.loaded()) {
self.loaded(true);
}
}
var isCurrent;
var now = new Date();
var currentSession = null;
var pastSession = null;
var upcomingSessions = [];
for (var i = 0; i < self.config.sessions.length; i++) {
if (((now - self.config.sessions[i].when) > -(self.config.anticipateSessionByMinutes * 60 * 1000)) && (now - self.config.sessions[i].when - (self.config.sessions[i].durationInMinutes * 60 * 1000)) <= (self.config.isRecentForMinutes * 60 * 1000)) {
pastSession = self.config.sessions[i];
}
isCurrent = ((now - self.config.sessions[i].when) > -(self.config.anticipateSessionByMinutes * 60 * 1000)) && ((now - self.config.sessions[i].when) < (self.config.sessions[i].durationInMinutes * 60 * 1000));
if (isCurrent && i < self.config.sessions.length - 1) {
isCurrent = (now - self.config.sessions[i+1].when) < -(self.config.anticipateSessionByMinutes * 60 * 1000);
}
if (!isCurrent) {
continue;
}
currentSession = self.config.sessions[i];
if (i > 0 && ((now - self.config.sessions[i-1].when - (self.config.sessions[i-1].durationInMinutes * 60 * 1000)) <= (self.config.isRecentForMinutes * 60 * 1000))) {
pastSession = self.config.sessions[i-1];
} else {
pastSession = null;
}
if (i < self.config.sessions.length -1) {
upcomingSessions = [];
var tracks = 0;
for (var j = i+1; j < Math.min(i+5, self.config.sessions.length); j++) {
if (tracks + self.config.sessions[j].tracks.length <= 3) {
tracks += self.config.sessions[j].tracks.length;
upcomingSessions.push(self.config.sessions[j]);
} else {
break;
}
}
}
break;
}
if (currentSession) {
var remainingMinutes = Math.ceil((currentSession.when - now) / 1000 / 60);
if (remainingMinutes <= 0) {
self.sessionStartingIn(self.labels.sessionUnderway);
} else {
self.sessionStartingIn(self.labels.sessionStartingIn[remainingMinutes == 1 ? 0 : 1].replace("{minutes}", remainingMinutes));
}
} else {
self.sessionStartingIn(null);
}
if (isSameSession(currentSession, self.currentSession()) && isSameSession(pastSession, self.pastSession()) && areSameSessions(upcomingSessions, self.upcomingSessions())) {
return;
}
changeSessions(pastSession, currentSession, upcomingSessions);
}
function isSameSession(session1, session2) {
if ((session1 == null && session2 != null) || (session1 != null && session2 == null)) {
return false;
}
if (session1 == null && session2 == null) {
return true;
}
var same = session1.when.getTime() == session2.when.getTime();
same = same && (session1.durationInMinutes == session2.durationInMinutes);
same = same && (session1.tracks.length == session2.tracks.length);
if (!same) {
return false;
}
for (var i = 0; i < session1.tracks.length; i++) {
same = same && (session1.tracks[i].who == session2.tracks[i].who);
same = same && (session1.tracks[i].what == session2.tracks[i].what);
}
return same;
}
function areSameSessions(sessions1, sessions2) {
if ((sessions1 == null && sessions2 != null) || (sessions1 != null && sessions2 == null)) {
return false;
}
if (sessions1 == null && sessions2 == null) {
return true;
}
if (sessions1.length != sessions2.length) {
return false;
}
var same = true;
for (var i = 0; i < sessions1.length; i++) {
same = same && isSameSession(sessions1[i], sessions2[i]);
}
return same;
}
function changeSessions(pastSession, currentSession, upcomingSessions) {
self.changingSession(true);
setTimeout(function() {
self.pastSession(pastSession);
self.currentSession(currentSession);
self.upcomingSessions(upcomingSessions);
}, 500);
setTimeout(function() { self.changingSession(false); }, 1500);
}
function getJson(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
//thanks to https://shashikantbhosale.wordpress.com/2013/07/17/javascript-convert-24-hour-clock-time-format-to-12-hour-time-clock-format/
self.formatTime = function(date) {
var hour = date.getHours(); /* Returns the hour (from 0-23) */
var minutes = date.getMinutes(); /* Returns the minutes (from 0-59) */
var result = hour;
var ext = '';
if(self.config.dateFormat == 12){
if(hour > 12){
ext = 'PM';
hour = (hour - 12);
if(hour < 10){
result = "0" + hour;
}else if(hour == 12){
hour = "00";
ext = 'AM';
}
}
else if(hour < 12){
result = ((hour < 10) ? "0" + hour : hour);
ext = 'AM';
}else if(hour == 12){
ext = 'PM';
}
} else {
if(hour < 10){
result = "0" + hour;
}
}
if(minutes < 10){
minutes = "0" + minutes;
}
result = result + ":" + minutes + ' ' + ext;
return result;
};
self.formatAudienceInitial = function(audience) {
return self.labels[audience + "Initial"];
};
self.formatAudience = function(audience) {
return self.labels[audience];
};
self.init = function() {
//updateSessions();
updateConfiguration();
setInterval(updateSessions, 5000);
setInterval(updateConfiguration, 60000);
};
}
var viewModel = new AgendaViewModel();
viewModel.init();
ko.applyBindings(viewModel);
//set container width
var containerWidth = /width=([0-9]+(%|px))/.exec(window.location.search);
if (containerWidth) {
document.getElementById("container").style.width = containerWidth[1];
} else {
function resizeContainer() {
var height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
document.getElementById("container").style.width = height / 864 * 1152;
}
window.onresize = resizeContainer;
resizeContainer();
}
</script>
</body>
</html>