Created
July 16, 2012 19:25
-
-
Save awagner83/3124504 to your computer and use it in GitHub Desktop.
CoffeeScript Translation of js in https://gist.github.com/3106865
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> | |
<ul id="albums-list"> | |
</ul> | |
<ul id="friends-list"> | |
</ul> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> | |
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script> | |
<script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script> | |
<script src="photos.js"></script> | |
</body> | |
</html> |
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
# Compile this with "coffee -c photos.coffee" to obtain the photos.js used in the html file above | |
Album = Backbone.Model.extend | |
id: null | |
cover_photo: null | |
name: null | |
created_time: null | |
Photo = Backbone.Model.extend | |
source: null | |
name: null | |
Albums = Backbone.Collection.extend | |
initialize: (models, options) -> @bind "add", options.view.addAlbumLi | |
Photos = Backbone.Collection.extend | |
initialize: (models, options) -> @bind "add", options.view.addPhotoLi | |
window.AppView = Backbone.View.extend | |
el: $("body") | |
initialize: () -> | |
@albums = new Albums null, {view: this} | |
@photos = new Photos null, {view: this} | |
$.ajax | |
url: "https://graph.facebook.com/203771702995922/albums" | |
dataType: "json" | |
success: (data, textStatus, jqXHR) => | |
$.each data['data'], (index, value) => | |
@albums.add(new Album value) | |
events: | |
"click #album-names": "showAlbum" | |
addPhotoLi: (model) -> | |
$("#friends-list").append('<img src="' + model.get('source') + '">') | |
addAlbumLi: (model) -> | |
$.ajax | |
url: "https://graph.facebook.com/" + model.get('cover_photo') | |
dataType: "json" | |
success: (data, textStatus, jqXHR) -> | |
$("#albums-list").append( | |
"<li><a href='#' id='#{model.get('id')}' class='album-names'> | |
<img src='#{data['picture']}'><br>#{model.get('name')} | |
</a></li>") | |
$("##{model.get('id')}").click () -> | |
$("#friends-list").empty() | |
$.ajax | |
url: "https://graph.facebook.com/#{this.id}/photos" | |
dataType: "json" | |
success: (data, textStatus, jqXHR) -> | |
$.each data['data'], (index, value) -> | |
appview.photos.add new Photo(value) | |
appview = new AppView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment