forked from pikooh/ubersicht-astronauts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.coffee
67 lines (55 loc) · 1.45 KB
/
index.coffee
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
command: 'curl -s "http://api.open-notify.org/astros.json"'
#refresh daily
refreshFrequency: 21000000
style: """
position: absolute
top: 20px
left: 20px
color: #fff
.output p,
.output ul
margin: 0
.output
font-family: Helvetica Neue
font-size: 20px
font-weight: 200
text-shadow: 0 1px 5px #000000;
ul li
font-size: 16px
#error
display: none
"""
render: (output) -> """
<div class="output">
<p id="success">
<span id="num">?</span> People in Space right now<br>
<ul id="people"></ul>
</p>
<p id="error">Not sure how many people are in space...</p>
</div>
"""
# credit goes to https://github.com/eanplatter/minimal-github-widgit
afterRender: (widget) ->
# this is a bit of a hack until jQuery UI is included natively
$.ajax({
url: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",
cache: true,
dataType: "script",
success: ->
$(widget).draggable()
return
})
update: (output, domEl) ->
try
jsonData = jQuery.parseJSON(output)
success = jsonData.message == "success"
catch e
success = false
$(domEl).find('#error').toggle( !success )
$(domEl).find('#success').toggle( success )
if success
numOfPeople = jsonData.number
$(domEl).find('#num').html numOfPeople
$(domEl).find('#people').html ""
for person in jsonData.people
$(domEl).find('#people').append '<li>'+person.name+' ('+person.craft+')</li>'