Sha256: c0f3876d477a578c29405745d80cac5aea7122aed8f53c572aaeb3d54e385d9a

Contents?: true

Size: 751 Bytes

Versions: 4

Compression:

Stored size: 751 Bytes

Contents

Teaspoon.hook = (name, payload = {}) ->

  xhr = null

  xhrRequest = (url, payload, callback) ->
    if window.XMLHttpRequest # Mozilla, Safari, ...
      xhr = new XMLHttpRequest()
    else if window.ActiveXObject # IE
      try xhr = new ActiveXObject("Msxml2.XMLHTTP")
      catch e
        try xhr = new ActiveXObject("Microsoft.XMLHTTP")
        catch e
    throw("Unable to make Ajax Request") unless xhr

    xhr.onreadystatechange = callback
    xhr.open("POST", "#{Teaspoon.root}/#{url}", false)
    xhr.setRequestHeader("Content-Type", "application/json")
    xhr.send(JSON.stringify(args: payload))

  xhrRequest "#{Teaspoon.suites.active}/#{name}", payload, ->
    return unless xhr.readyState == 4
    throw JSON.parse(xhr.response).err

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
teaspoon-1.4.0 app/assets/javascripts/teaspoon/hook.coffee
teaspoon-1.2.2 app/assets/javascripts/teaspoon/hook.coffee
teaspoon-1.2.1 app/assets/javascripts/teaspoon/hook.coffee
teaspoon-1.2.0 app/assets/javascripts/teaspoon/hook.coffee