define -> DropdownModel = Backbone.Model.extend select: -> @collection.each (model) => model.set( 'selected', model == @ ) @trigger('option-clicked',@) DropdownCollection = Backbone.Collection.extend model: DropdownModel DropdownView = Backbone.View.extend tagName: 'div' className: 'dropdown' events: "click .drop-indicator": 'clickedDrop' "click .button": 'clickedItem' initialize: -> @collection = new DropdownCollection() @collection.on 'all', _.bind(@render,@) # hackery :( $('body').on 'click', _.bind(@clickedOutsideDropdown,@) selectedModel: -> selected = @collection.find (m)-> m.get('selected') selected || @collection.at(0) unselectedModels: -> _(@collection.reject (m)-> m.get('selected')) createButtonFor: (model)-> $("""""") .on 'click', => @clickedItem(model) render: -> @$el .empty() .append( @createButtonFor(@selectedModel()) ) .append( $ul = $("