diff options
author | Daniel Beauchamp <daniel.beauchamp@shopify.com> | 2012-07-24 15:25:22 -0400 |
---|---|---|
committer | Daniel Beauchamp <daniel.beauchamp@shopify.com> | 2012-07-24 15:30:32 -0400 |
commit | c63c8f1698e8c059e286fb49ba0264e4336a6e33 (patch) | |
tree | 372fa45a424f4de805112995be3e0074ce9e0125 /vendor/javascripts/application.coffee | |
parent | 9f625f927aadf6d9574bd968d2cfc29dde5551c0 (diff) |
Initial version. 0.1.0 Release
Diffstat (limited to 'vendor/javascripts/application.coffee')
-rw-r--r-- | vendor/javascripts/application.coffee | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/javascripts/application.coffee b/vendor/javascripts/application.coffee new file mode 100644 index 0000000..54050c6 --- /dev/null +++ b/vendor/javascripts/application.coffee @@ -0,0 +1,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()
\ No newline at end of file |