Sha256: 7fa37bdd241b3573508c1e39009a420f21716d3810b8f5d7ea92b9715b5fc8b0

Contents?: true

Size: 799 Bytes

Versions: 1

Compression:

Stored size: 799 Bytes

Contents

Teaspoon.hook = (name, payload = {}) ->
  method = "POST"
  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("Unable to call hook \"#{url}\".") unless xhr.status == 200

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teaspoon-0.9.0 app/assets/javascripts/teaspoon/base/hook.coffee