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

32 lines
621 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: '/'
debug: false
2012-03-13 17:21:32 +00:00
ping: ->
Flowerbox.contact('ping')
2012-03-02 18:28:52 +00:00
contact: (url, data...) ->
if !Flowerbox.debug
attempts = 3
2012-03-13 17:21:32 +00:00
doContact = ->
attempts -= 1
2012-03-13 17:21:32 +00:00
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()
2012-03-13 17:21:32 +00:00
doContact()
2012-03-03 16:28:03 +00:00
fail: ->
2012-03-13 17:21:32 +00:00