This repository was archived by the owner on Jul 28, 2018. It is now read-only.

Description
I've got an implementation of turboforms working which hijacks all 'normal' forms on the page and sends then asynchronously, replacing the body with the result. This example is rails-specific but could be made generic:
extractUrlTitleAndBody = (content) ->
doc = createDocument content
url = doc.querySelector('meta[name=currentPath]').getAttribute('content')
title = doc.querySelector 'title'
[ url, title?.textContent, doc.body ]
setContent = (url, title, body) ->
cacheCurrentPage()
reflectNewUrl url
changePage title, body
turboforms = () ->
$('form:not([data-remote]),a[data-turboform]').each (index, el) =>
el = $(el)
el.attr('data-remote', 'true')
el.bind 'ajax:beforeSend', (event, data, status, xhr) =>
triggerEvent 'page:fetch'
el.bind '[RemoteForm] ajax:success', (event, data, status, xhr) =>
setContent extractUrlTitleAndBody(xhr.responseText)...
triggerEvent 'page:load'
It raises two questions
- is turboforms something people want?
- this could be made as an extension to turbolinks (this is kind of how I'm hooking into it). The turbolinks api doesn't really allow for this at present but could easily be exposed to allow for extensions like this