Skip to content

Instantly share code, notes, and snippets.

@reinh
Created February 10, 2011 16:45
Show Gist options
  • Select an option

  • Save reinh/820861 to your computer and use it in GitHub Desktop.

Select an option

Save reinh/820861 to your computer and use it in GitHub Desktop.
Twitter = Views: {}
class Twitter.Model extends Backbone.Model
class Twitter.Collection extends Backbone.Collection
url: 'http://search.twitter.com/search.json?rpp=10&q=phpfog&callback=?'
model: Twitter.Model
parse: (response) -> response.results
class Twitter.Views.index extends Backbone.View
el: $('#twitter')
initialize: ->
_.bindAll @, 'refresh', 'render', 'add'
@collection = @options.collection
@collection.bind 'refresh', @refresh
@collection.bind 'add', @add
refresh: ->
$(@el).empty()
@collection.each(@add)
@el.twitterCarousel()
add: (tweet) ->
view = new Twitter.Views._list_item
model: tweet
@el.append view.render().el
class Twitter.Views._list_item extends Backbone.View
tagName: 'li'
className: 'queue'
template: _.template($('#twitter-template').html())
render: ->
$(@el).html @template(@model.toJSON())
@.$('p').autolink()
@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment