-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh.html
74 lines (65 loc) · 2.76 KB
/
refresh.html
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
<!DOCTYPE html>
<html>
<head><title></title></head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>
<button type="button" class="btn state-button"> unknown </button>
<script type="application/javascript">
// see https://github.com/nova-labs/event_service_web_examples for more possibilities
var doorStatusUrl= "//event.nova-labs.org/events/novalabs_space/latest";
var doorUpdateDelay= 300000; // milliseconds
var doorStatusLimit= new Date().getTime()+doorUpdateDelay;
var doorStatusScheduled= 0;
function eventToStatus(event) {
var red= {'background-color': '#da4f49', 'background-image': '-webkit-linear-gradient(top, #ee5f5b, #bd362f)', padding: '4px 10px 4px', 'text-shadow': '0 -1px 0 rgba(0, 0, 0, 0.25)', color: 'white', 'border-radius': '.25rem'};
var green= {'background-color': '#5bb75b', 'background-image': '-webkit-linear-gradient(top, #62c462, #51a351)', padding: '4px 10px 4px', 'text-shadow': '0 -1px 0 rgba(0, 0, 0, 0.25)', color: 'white', 'border-radius': '.25rem'};
if (event) {
if ('open' == event.value) {
return {text: "OPEN", css: green, time: new Date(event.epochMillis)};
} else if ('closed' == event.value) {
return {text: "CLOSED", css: red, time: new Date(event.epochMillis)};
}
}
return {text: "UNKNOWN", css: red, time: new Date(0)};
}
function shortDateTime(when) {
var date= when.toDateString().split(' ');
var mon= date[1];
var day= date[2];
var time= when.toTimeString().split(' ')[0].split(':');
var hr= time[0];
var mn= time[1];
return [mon,day,[hr,mn].join(':')].join(' ');
}
function showDoorStatus() {
jQuery.getJSON(doorStatusUrl, function( event ) {
var status = eventToStatus(event);
jQuery(".state-button").html(status.text + "<br/>" + shortDateTime(status.time)).css(status.css);
});
}
function doorStatusTimeout() {
showDoorStatus();
if (doorStatusLimit > new Date().getTime()) {
setTimeout(doorStatusTimeout, doorUpdateDelay);
doorStatusScheduled= 1;
} else {
doorStatusScheduled= 0;
}
}
function doorUserActive() {
if (!doorStatusScheduled) {
var wait= doorStatusLimit - new Date().getTime();
if (wait <= 0) {
showDoorStatus();
wait= doorUpdateDelay;
}
setTimeout(doorStatusTimeout, wait);
doorStatusScheduled= 1;
}
doorStatusLimit= new Date().getTime()+doorUpdateDelay;
}
jQuery(showDoorStatus);
jQuery(document).mousemove(doorUserActive);
</script>
</body>
</html>