Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
@adambiggs adambiggs
48 lines (35 sloc) 0.919 kb
Spine = @Spine or require('spine')
$ = Spine.$
class Spine.List extends Spine.Controller
events:
'click .item': 'click'
selectFirst: false
constructor: ->
super
@bind 'change', @change
template: ->
throw Error 'Override template'
change: (item) =>
@current = item
unless @current
@children().removeClass('active')
return
@children().removeClass('active')
for item, idx in @items when item is @current
index = idx
break
$(@children().get(index)).addClass('active')
render: (items) ->
@items = items if items
@html @template(@items)
@change @current
if @selectFirst
unless @children('.active').length
@children(':first').click()
children: (sel) ->
@el.children(sel)
click: (e) ->
item = @items[$(e.currentTarget).index()]
@trigger('change', item)
true
module?.exports = Spine.List
Jump to Line
Something went wrong with that request. Please try again.