grimwire/local — pull request #39 by pfraze (2013-04-17 23:48:31+00:00)
Title: Add the "application/html-deltas+json" response type behaviors

*From the documentation:*

Occasionally, server responses need to make targeted updates to the UI, in order to avoid losing the state of form elements. This is accomplished by responding to an html request with the "application/html-delta+json" type.

```html
//...
respond.ok('application/html-delta+json').end({
replace: {
'.messages': buildMessagesHTML(),
'.toolbar .last-update': 'Connected at '+getDateString()+''
},
addClass: {
'.toolbar .connect': 'disabled'
},
removeClass: {
'.toolbar .disconnect': 'disabled'
}
});
//...
```

The schema of an html-delta follows the form of { operation: { selector: content } }. The list of supported operations is:

- replace: set the selector target's innerHTML to the content
- append: add the content to the end of the selector target's innerHTML
- prepend: add the content to the beginning of the selector target's innerHTML
- addClass: add the content to the selector target's class
- removeClass: remove the content from the selector target's class
- toggleClass: toggle the content in the selector target's class

Additional tips:

- The Link.Responder class (used above) aliases "html-deltas" to "application/html-deltas+json", allowing you to write respond.ok("html-deltas").