documentcloud/backbone — Issue #877: Backbone.View.bridge - create Backbone views with jQuery syntax
Author: meleyal
Created: 2012-01-19 17:57:19+00:00
State: open

This is a helper method for creating Backbone views with jQuery syntax.

It uses the [jquery.ui widget factory](http://ajpiano.com/widgetfactory/) to attach Backbone views to the jquery.fn namespace, allowing them to be called like regular jquery plugins (e.g. `$('.slideshow').slideshow(options)`)

The gist is here: https://gist.github.com/1641439

It's pretty crude, but maybe something similar could be rolled in to Backbone?

### Example (coffeescript):

```coffeescript

# Include bridge method (requires jquery.ui)

Backbone.View.bridge = (klass) ->
bridge = (options, el) -> new klass({ el, options })
camel = (string) -> return string.charAt(0).toLowerCase() + string.slice(1)
$.widget.bridge(camel(klass.name), klass)

# In your view

class Slideshow extends Backbone.View
... etc.

Backbone.View.bridge(Slideshow) # outside the view class

# On ready

$(document).ready ->
$('.slideshow').slideshow()

````