Skip to content

Instantly share code, notes, and snippets.

@dannyamey
Created April 16, 2012 14:56
Show Gist options
  • Save dannyamey/2399266 to your computer and use it in GitHub Desktop.
Save dannyamey/2399266 to your computer and use it in GitHub Desktop.
<script>
var Movie = Backbone.Model.extend({
});
var MovieList = Backbone.Collection.extend({
model: Movie
});
var GridView = Backbone.View.extend({
el: '#main',
template: Handlebars.compile(MagicLantern.templates.movie_items),
initialize: function(){
this.collection.bind('reset change', this.render, this);
},
render: function(movie){
this.$el.html(this.template(movie.toJSON()));
return this;
},
});
var SidebarView = Backbone.View.extend({
el: this.$('#sidebar'),
events: {
"click ul.nav a": "changeGenre"
},
changeGenre: function(e){
this.collection.url = e.currentTarget.href;
this.collection.fetch();
return false;
}
});
$(function(){
var MagicLantern = {};
MagicLantern.movieList = new MovieList({{{ movies }}});
MagicLantern.gridView = new GridView({
collection: MagicLantern.movieList
});
MagicLantern.sidebarView = new SidebarView({
collection: MagicLantern.movieList
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment