Skip to content

Commit

Permalink
Merge pull request #1 from intothev01d/config
Browse files Browse the repository at this point in the history
Config settings for interval and fix for ticker colors
  • Loading branch information
ahmetabdi committed Mar 13, 2014
2 parents 28ce2e7 + a04cdb5 commit 08344bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/atom-bitcoin-status-bar-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ jQuery = require 'jquery'

module.exports =
class AtomBitcoinStatusBarView extends View
default_interval: 5000
load_text: 'Retreiving price...'

@content: ->
@div class: 'inline-block', =>
@span outlet: "bitcoinInfo", class: 'atom-bitcoin-status', tabindex: '-1', ""
Expand All @@ -19,23 +22,37 @@ class AtomBitcoinStatusBarView extends View
, 1

afterAttach: ->
# Get user settings for interval
# Insure it's a number then convert to milliseconds or use default
interval = atom.config.get('atom-bitcoin.interval')
interval = if not isNaN(interval) then (interval.toFixed() * 1000) else @default_interval

# Display loading text
@display(null)

output = undefined
last_output = undefined
setInterval =>
jQuery ($) ->
json = $.getJSON "https://api.bitcoinaverage.com/ticker/USD/last", '', (data, resp) ->
if resp = "success"
output = parseFloat(data).toFixed(2)
if output < last_output
if output > last_output
$(".atom-bitcoin-status").css "color", "green"
else if output > last_output
else if output < last_output
$(".atom-bitcoin-status").css "color", "red"
else

else
#Handle failed response?

@bitcoinInfo.text("$#{output}")
# Update price
@display(output)
last_output = output

, 5000
, interval # config or default interval


display: (price) ->
# Display loading text or current price
@bitcoinInfo.text(if not price then @load_text else "$#{price}")
3 changes: 3 additions & 0 deletions lib/atom-bitcoin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ AtomBitcoinStatusBarView = require './atom-bitcoin-status-bar-view'
module.exports =
activate: ->
@atomBitcoinStatusBarView = new AtomBitcoinStatusBarView()

configDefaults:
interval: 5

0 comments on commit 08344bb

Please sign in to comment.