Shopify/turbograft — pull request #35 by pseudomuto (2014-11-09 21:21:41+00:00)
Title: Adding turbograft:remote:init Event

@nsimmons, @qq99 and @tylermercier

Adding a `turbograft:remote:init` event to allow callers to alter the xhr before it is sent. This is useful when we want to add the CSRF token header for example.

_This hasn't been a problem in Shopify so far, because we're using [this](https://github.com/Shopify/shopify/blob/97d05fa6f1d946d90efdef7522bcc6c7af713067/app/assets/javascripts/admin/lib/remote.coffee) rather than `Turbograft.Remote`. That allows use to continue to use the `$.ajaxSetup` method we have there._

# Sample Usage

```coffeescript
$(document).on "turbograft:remote:init", (event) ->
token = $("meta[name=csrf-token]").attr("content")
event.originalEvent.data.xhr.setRequestHeader("X-CSRF-Token", token)
```

I've also added the event description to the example app