Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

78 lines (70 sloc) 2.59 kb
do (Backbone) ->
Backbone.Binding['visible'] = class VisibleBinding extends Backbone.Binding
initialize: (@attribute) ->
onModelChange: ->
val = @viewModel.get(@attribute)
if val then return $(@node).show()
return $(@node).hide()
Backbone.Binding['text'] = class TextBinding extends Backbone.Binding
initialize: (@attribute) ->
onModelChange: ->
val = @viewModel.get(@attribute)
Backbone.Binding['val'] = class ValueBinding extends Backbone.Binding
initialize: (@attribute) ->
start: ->
$(@node).on('keyup change', @onViewChange)
onModelChange: ->
val = @viewModel.get(@attribute)
onViewChange: ->
val = $(@node).val()
@viewModel.set(@attribute, val)
stop: ->
$(@node).off('keyup change', @onViewChange)
Backbone.Binding['css'] = class CssBinding extends Backbone.Binding
initialize: (@className, @attribute, @truth = true) ->
onModelChange: ->
val = @viewModel.get(@attribute)
if Boolean(@truth) == Boolean(val)
return $(@node).addClass(@className)
return $(@node).removeClass(@className)
Backbone.Binding['click'] = class ClickBinding extends Backbone.Binding
initialize: ->
args = _.toArray(arguments)
@callback = args.shift()
@args = args
start: ->
$(@node).on('click', @onViewChange)
onViewChange: (event) ->
callback = @viewModel[@callback] ? @viewModel.get(@callback)
callback.apply(@viewModel, @args)
stop: ->
$(@node).off('click', @onViewChange)
Backbone.Binding['each'] = class EachBinding extends Backbone.Binding
initialize: (@attr) ->
@container = $(@node)
@itemTemplate = @container.html()
start: ->
@viewModel.on('change:' + @attr, @onCollectionChange)
onCollectionChange: ->
self = this
@collection = @viewModel.get(@attr)
if @collection instanceof Backbone.Collection'add remove reset create sort', @onCollectionChange);
@collection.on('add remove reset create sort', @onCollectionChange);
@renderItem(item) for item in @collection
renderItem: (viewModel) =>
for node in $(@itemTemplate)
viewModel.bindView(@bindingAttr, node)
stop: ->'change:' + @attr, @onCollectionChange)
Jump to Line
Something went wrong with that request. Please try again.