Skip to content
Browse files

Making it easier to follow

  • Loading branch information...
1 parent 1feabe2 commit 1583bd12da078fc481b6886fe26d45dded1ca769 @jonmaim committed
Showing with 34 additions and 22 deletions.
  1. +5 −0 index.html
  2. +8 −3 js/app.js
  3. +6 −9 js/collections/friends.js
  4. +5 −2 js/models/friend.js
  5. +3 −0 js/models/winners.js
  6. +4 −5 js/views/friends.js
  7. +3 −3 js/views/landing.js
View
5 index.html
@@ -75,15 +75,20 @@
</div>
</script>
+ <!-- Vendor. -->
<script src="//connect.facebook.net/en_US/all.js"></script>
<script src="js/vendor/jquery-1.7.1.min.js"></script>
<script src="js/vendor/underscore.js"></script>
<script src="js/vendor/backbone.js"></script>
+ <!-- Models. -->
<script src="js/models/winners.js"></script>
<script src="js/models/friend.js"></script>
+ <!-- Collections. -->
<script src="js/collections/friends.js"></script>
+ <!-- Views. -->
<script src="js/views/landing.js"></script>
<script src="js/views/friends.js"></script>
+ <!-- App. -->
<script src="js/app.js"></script>
<script>
/* App start. */
View
11 js/app.js
@@ -10,11 +10,16 @@ $(function(){
}
, initialize: function(){
console.log('router:initialize');
- /* Views. */
+ /* Models. */
+ this.winnersModel = new WinnersModel();
+ /* Collections.*/
this.friendsCollection = new FriendsCollection();
- this.landingView = new LandingView({ collection: this.friendsCollection });
+ /* Views. */
+ this.landingView = new LandingView({
+ collection: this.friendsCollection
+ });
this.friendsView = new FriendsView({
- model : new WinnersModel()
+ model : this.winnersModel
, collection: this.friendsCollection
});
/* Event binding. */
View
15 js/collections/friends.js
@@ -1,28 +1,25 @@
window.FriendsCollection = Backbone.Collection.extend({
- model:  Friend
- , from: 0
- , offset: 6
- , initialize: function(opts){
- console.log('Friends:initialize');
+ model:  FriendModel
+ , from: 0
+ , offset: 6
+ , access_token: null
+ , initialize: function(){
+ console.log('FriendsCollection:initialize');
}
, url: function(){
- //console.log('Friends:url');
return 'https://graph.facebook.com/me/friends?access_token='+this.access_token;
}
, parse: function(res) {
- //console.log('Friends:parse');
res.data.sort(function(a,b){
return (a.name.toLowerCase() < b.name.toLowerCase()) ? -1 : 1;
});
return res.data;
}
, next: function(){
- console.log('from',this.from);
this.from += this.offset;
this.trigger('changePage');
}
, prev: function(){
- console.log('from',this.from);
this.from -= this.offset;
this.trigger('changePage');
}
View
7 js/models/friend.js
@@ -1,5 +1,8 @@
-window.Friend = Backbone.Model.extend({
+window.FriendModel = Backbone.Model.extend({
initialize: function(){
- console.log('Friend:initialize');
+ console.log('FriendModel:initialize');
}
});
+
+
+
View
3 js/models/winners.js
@@ -33,3 +33,6 @@ window.WinnersModel = Backbone.Model.extend({
}
}
});
+
+
+
View
9 js/views/friends.js
@@ -5,8 +5,8 @@ window.FriendsView = Backbone.View.extend({
_.bindAll(this, 'render');
this.template = _.template( $('#friends_view_template').html() );
/* Event bindings. */
+ this.model.bind('change', this.render);
this.collection.bind('reset', this.render);
- this.model.bind('change', this.render);
}
, events : {
'click input[type=checkbox]' : 'clickChoice'
@@ -15,7 +15,7 @@ window.FriendsView = Backbone.View.extend({
, 'click #next' : 'clickNext'
},
render : function(){
- console.log('FriendsView:render',this.model.full);
+ console.log('FriendsView:render');
this.$el.html( this.template({
winners: this.model.toJSON()
, friends:  this.collection.toJSON()
@@ -47,9 +47,8 @@ window.FriendsView = Backbone.View.extend({
caption: 'My best friends are: '+friendsName,
description: 'Oh yeah!'
};
- console.log(params);
- FB.ui(params, function(res){
- console.log(res);
+ FB.ui(params, function(res){
+ //console.log(res);
});
return false;
}
View
6 js/views/landing.js
@@ -2,6 +2,7 @@ window.LandingView = Backbone.View.extend({
el : '#view_entry'
, initialize : function(){
console.log('LandingView:initialize');
+ this.template = _.template( $('#landing_view_template').html() );
FB.init({
appId : '301452643259358'
, status : true
@@ -9,12 +10,11 @@ window.LandingView = Backbone.View.extend({
, xfbml : true
, oauth : true
});
- this.template = _.template( $('#landing_view_template').html() );
}
, events : {
'click #login_btn' : 'clickLoginBtn'
- },
- render : function(){
+ }
+ , render : function(){
console.log('LandingView:render');
this.$el.html( this.template() );
return this;

0 comments on commit 1583bd1

Please sign in to comment.
Something went wrong with that request. Please try again.