a little js cleanup for post.js
This commit is contained in:
parent
0fbf366ef1
commit
039b65b5cc
2 changed files with 24 additions and 27 deletions
|
|
@ -5,34 +5,31 @@
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var Post = function() {
|
var Post = function() {
|
||||||
this.likesSelector = ".like_it, .dislike_it";
|
var self = this;
|
||||||
this.expandLikesSelector = "a.expand_likes, a.expand_dislikes";
|
//timeago //set up ikes //comments //audio video links //embedder //
|
||||||
|
|
||||||
this.start = function() {
|
this.start = function() {
|
||||||
//timeago
|
$.extend(self, {
|
||||||
//set up ikes
|
likes: {
|
||||||
//comments
|
actions: $(".like_it, .dislike_it"),
|
||||||
//audio video links
|
expanders: $("a.expand_likes, a.expand_dislikes"),
|
||||||
//embedder
|
}
|
||||||
//
|
});
|
||||||
|
self.setUpLikes();
|
||||||
|
},
|
||||||
this.setUpLikes();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.setUpLikes = function() {
|
this.setUpLikes = function() {
|
||||||
$(this.expandLikesSelector).live("click", this.expandLikes);
|
self.likes.expanders.live("click", self.expandLikes);
|
||||||
|
self.likes.actions.live("ajax:loading", function() {
|
||||||
var likeIt = $(this.likesSelector);
|
$(this).parent().fadeOut(100);
|
||||||
|
|
||||||
likeIt.live("ajax:loading", function() {
|
|
||||||
$(this).parent().fadeOut("fast");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
likeIt.live("ajax:failure", function() {
|
self.likes.actions.live("ajax:failure", function() {
|
||||||
Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t("failed_to_like"));
|
Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t("failed_to_like"));
|
||||||
$(this).parent().fadeIn("fast");
|
$(this).parent().fadeIn(100);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.expandLikes = function(evt){
|
this.expandLikes = function(evt){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var likesList = $(this).siblings(".likes_list");
|
var likesList = $(this).siblings(".likes_list");
|
||||||
|
|
@ -41,13 +38,13 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.href,
|
url: this.href,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
likesList.html(data);
|
likesList.html(data)
|
||||||
likesList.fadeToggle("fast");
|
.fadeToggle(100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else {
|
}
|
||||||
likesList
|
else {
|
||||||
.fadeToggle("fast");
|
likesList.fadeToggle(100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@ describe("Diaspora", function() {
|
||||||
it("adds a listener for the click event on a.expand_likes", function() {
|
it("adds a listener for the click event on a.expand_likes", function() {
|
||||||
spyOn(window, "$").andCallThrough();
|
spyOn(window, "$").andCallThrough();
|
||||||
Diaspora.widgets.post.start();
|
Diaspora.widgets.post.start();
|
||||||
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.expandLikesSelector);
|
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.likes.expanders);
|
||||||
$.reset();
|
$.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds a listener for ajax:success and ajax:failure", function() {
|
it("adds a listener for ajax:success and ajax:failure", function() {
|
||||||
spyOn(window, "$").andCallThrough();
|
spyOn(window, "$").andCallThrough();
|
||||||
Diaspora.widgets.post.start();
|
Diaspora.widgets.post.start();
|
||||||
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.likesSelector);
|
expect($).toHaveBeenCalledWith(Diaspora.widgets.post.likes.actions);
|
||||||
$.reset();
|
$.reset();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue