flowerbox/lib/assets/javascripts/flowerbox.js.coffee
2012-03-13 13:21:32 -04:00

36 lines
675 B
CoffeeScript

#= require_self
#= require flowerbox/result
#= require flowerbox/exception
#
Flowerbox =
baseUrl: '/'
ping: ->
Flowerbox.contact('ping')
pause: (time) ->
t = (new Date()).getTime()
while (t + time) > (new Date().getTime())
Flowerbox.ping()
contact: (url, data...) ->
attempts = 3
doContact = ->
attempts -= 1
try
xhr = new XMLHttpRequest()
xhr.open("POST", Flowerbox.baseUrl + url, false)
xhr.setRequestHeader("Accept", "application/json")
xhr.send(JSON.stringify(data))
catch e
if attempts == 0
throw e
else
doContact()
doContact()
fail: ->