flowerbox/lib/assets/javascripts/flowerbox.js.coffee

36 lines
675 B
CoffeeScript
Raw Normal View History

2012-03-13 17:21:32 +00:00
#= require_self
#= require flowerbox/result
#= require flowerbox/exception
#
2012-03-02 18:28:52 +00:00
Flowerbox =
baseUrl: '/'
2012-03-13 17:21:32 +00:00
ping: ->
Flowerbox.contact('ping')
pause: (time) ->
t = (new Date()).getTime()
while (t + time) > (new Date().getTime())
Flowerbox.ping()
2012-03-02 18:28:52 +00:00
contact: (url, data...) ->
2012-03-13 17:21:32 +00:00
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()
2012-03-03 16:28:03 +00:00
fail: ->
2012-03-13 17:21:32 +00:00