Created
July 19, 2012 14:00
-
-
Save awagner83/3144111 to your computer and use it in GitHub Desktop.
Broken-up backbone test
This file contains hidden or 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
$(function() { | |
var Album, AlbumList, AlbumView, Albums, App, AppView; | |
Album = Backbone.Model.extend({ | |
defaults: function() { | |
return { | |
source: null, | |
name: 'Unnamed Album' | |
}; | |
} | |
}); | |
AlbumList = Backbone.Collection.extend({ | |
url: "https://graph.facebook.com/203771702995922/albums", | |
model: Album, | |
parse: function(response) { | |
return response['data']; | |
} | |
}); | |
Albums = new AlbumList; | |
AlbumView = Backbone.View.extend({ | |
tagname: "li", | |
template: _.template($("#album_template").html()), | |
render: function() { | |
this.$el.html(this.template(this.model.toJSON())); | |
return this; | |
} | |
}); | |
AppView = Backbone.View.extend({ | |
el: $("#app"), | |
initialize: function() { | |
Albums.bind('reset', this.addAllAlbumns, this); | |
return Albums.fetch(); | |
}, | |
addAllAlbums: function() { | |
console.log("I'm here!"); | |
return Albums.each(this.addOneAlbum); | |
}, | |
addOneAlbum: function(album) { | |
var view; | |
view = new AlbumView({ | |
model: album | |
}); | |
return $("#albums").append(view.render().el); | |
}, | |
render: function() { | |
return console.log(Albums); | |
} | |
}); | |
App = new AppView; | |
}); |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Backbone with Mighty Moo Photos</title> | |
</head> | |
<body> | |
<div id="app"> | |
<ul id="albums"> | |
</ul> | |
</div> | |
<script type="text/template" id="album_template"> | |
<div class="album"> | |
<img src="<%= cover_src %>"> | |
<span class="title"><%= name %></span> | |
</div> | |
</script> | |
<script type="text/template" id="photo_template"> | |
<div class="photo"> | |
<img src="<%= picture %>"> | |
</div> | |
</script> | |
<script src="jquery-1.7.2.js"></script> | |
<script src="underscore.js"></script> | |
<script src="backbone.js"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment