-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlite.html
45 lines (39 loc) · 1.84 KB
/
lite.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
<!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 url= "//event.nova-labs.org/events/novalabs_space/latest";
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(' ');
}
jQuery(function() {
jQuery.getJSON(url, function( event ) {
var status = eventToStatus(event);
jQuery(".state-button").html(status.text + "<br/>" + shortDateTime(status.time)).css(status.css);
});
});
</script>
</body>
</html>