1.0.2 • Published 9 years ago

backbone-elements v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

backbone-elements

Build Status

Tested with Backbone 1.1.2

This library allows you to easily define and use child elements within your Backbone views:

class View extends Backbone.View
  elements:
    ".status": "status"
    ".child-element > div": "childDiv"

  events:
    "click a.another-div": "_clickHandler"

  initialize: ->
    super // parent initialize() calls @refreshElements()
    console.log 'started'

  # use the references in functions
  _clickHandler: ->
    @$status.text "clicked"
    @$childDiv.remove()

    @refreshElements() # refresh element references

You can change the default element prefix too:

class View extends Backbone.View
  elementPrefix: ''

  elements:
    ".status": "status"
    ".child-element > div": "childDiv"

  events:
    "click a.another-div": "_clickHandler"

  initialize: ->
    super // parent initialize() calls @refreshElements()
    console.log 'started'

  # use the references in functions
  _clickHandler: ->
    @status.text "clicked"
    @childDiv.remove()

    @refreshElements() # refresh element references

node.js

Install using npm:

$ npm install backbone-elements

Browser

Use bower:

$ bower install backbone-elements

Building

To build the code and run the tests:

$ npm install -g gulp
$ npm install
$ gulp

Contributing

Contributions are welcome! Please see CONTRIBUTING.md.

License

MIT - see LICENSE.md