Skip to content

Commit

Permalink
a little js cleanup for post.js
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrippi committed Jul 12, 2011
1 parent 0fbf366 commit 039b65b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
47 changes: 22 additions & 25 deletions public/javascripts/widgets/post.js
Expand Up @@ -5,34 +5,31 @@

(function() {
var Post = function() {
this.likesSelector = ".like_it, .dislike_it";
this.expandLikesSelector = "a.expand_likes, a.expand_dislikes";
this.start = function() {
//timeago
//set up ikes
//comments
//audio video links
//embedder
//

var self = this;
//timeago //set up ikes //comments //audio video links //embedder //

this.setUpLikes();
};
this.start = function() {
$.extend(self, {
likes: {
actions: $(".like_it, .dislike_it"),
expanders: $("a.expand_likes, a.expand_dislikes"),
}
});
self.setUpLikes();
},

this.setUpLikes = function() {
$(this.expandLikesSelector).live("click", this.expandLikes);

var likeIt = $(this.likesSelector);

likeIt.live("ajax:loading", function() {
$(this).parent().fadeOut("fast");
self.likes.expanders.live("click", self.expandLikes);
self.likes.actions.live("ajax:loading", function() {
$(this).parent().fadeOut(100);
});

likeIt.live("ajax:failure", function() {
self.likes.actions.live("ajax:failure", function() {
Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t("failed_to_like"));
$(this).parent().fadeIn("fast");
$(this).parent().fadeIn(100);
});
};

this.expandLikes = function(evt){
evt.preventDefault();
var likesList = $(this).siblings(".likes_list");
Expand All @@ -41,13 +38,13 @@
$.ajax({
url: this.href,
success: function(data){
likesList.html(data);
likesList.fadeToggle("fast");
likesList.html(data)
.fadeToggle(100);
}
});
}else {
likesList
.fadeToggle("fast");
}
else {
likesList.fadeToggle(100);
}
};
};
Expand Down
4 changes: 2 additions & 2 deletions spec/javascripts/widgets/post-spec.js
Expand Up @@ -17,14 +17,14 @@ describe("Diaspora", function() {
it("adds a listener for the click event on a.expand_likes", function() {
spyOn(window, "$").andCallThrough();
Diaspora.widgets.post.start();
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.expandLikesSelector);
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.likes.expanders);
$.reset();
});

it("adds a listener for ajax:success and ajax:failure", function() {
spyOn(window, "$").andCallThrough();
Diaspora.widgets.post.start();
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.likesSelector);
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.likes.actions);
$.reset();
});
});
Expand Down

0 comments on commit 039b65b

Please sign in to comment.