blob: 54050c637b67daed3eb70f1e1cf92a6eb330ae52 (
plain)
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
|
Batman.Filters.PrettyNumber = (num) ->
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") unless isNaN(num)
class window.AllTheThings extends Batman.App
@root ->
Batman.Property.EasingSetter =
get: Batman.Property.defaultAccessor.get
set: (k, to) ->
if isNaN(to)
@[k] = to
else
timer = "interval_#{k}"
num = if !isNaN(@[k]) then @[k] else 0
unless @[timer] || num == to
up = to > num
num_interval = Math.abs(num - to) / 90
@[timer] =
setInterval =>
num = if up then Math.ceil(num+num_interval) else Math.floor(num-num_interval)
if (up && num > to) || (!up && num < to)
num = to
clearInterval(@[timer])
@[timer] = null
delete @[timer]
@[k] = num
@set k, to
@[k] = num
AllTheThings.widgets = widgets = {}
AllTheThings.lastEvents = lastEvents = {}
source = new EventSource('/events')
source.addEventListener 'open', (e)->
console.log("Connection opened")
source.addEventListener 'error', (e)->
console.log("Connection error")
if (e.readyState == EventSource.CLOSED)
console.log("Connection closed")
source.addEventListener 'message', (e) =>
data = JSON.parse(e.data)
lastEvents[data.id] = data
if widgets[data.id]?.length > 0
for widget in widgets[data.id]
widget.onData(data)
$(document).ready ->
AllTheThings.run()
|