Created
April 16, 2012 14:56
-
-
Save dannyamey/2399266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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