MS DH fix liking of posts and comment js; instansiate streamElement widgets when they are socketed

This commit is contained in:
Maxwell Salzberg 2011-09-03 12:09:21 -07:00
parent 1a823d647e
commit eb6263084e
9 changed files with 29 additions and 20 deletions

View file

@ -21,7 +21,8 @@
= comment.created_at ? timeago(comment.created_at) : timeago(Time.now)
.likes
= render "likes/likes_container", :target_id => comment.id, :likes_count => comment.likes_count, :target_type => "Comment"
.likes_container
= render "likes/likes_container", :target_id => comment.id, :likes_count => comment.likes_count, :target_type => "Comment"
- unless !user_signed_in? || @commenting_disabled
%span.like_action

View file

@ -2,13 +2,11 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.likes_container
- if likes_count > 0
= image_tag('icons/heart.svg')
- if target_type == "Comment"
= link_to t('likes.likes.people_like_this_comment', :count => likes_count), comment_likes_path(target_id), :class => "expand_likes"
- else
= link_to t('likes.likes.people_like_this', :count => likes_count), post_likes_path(target_id), :class => "expand_likes"
%span.hidden.likes_list
/= render 'likes/likes', :likes => likes
- if likes_count > 0
= image_tag('icons/heart.svg')
- if target_type == "Comment"
= link_to t('likes.likes.people_like_this_comment', :count => likes_count), comment_likes_path(target_id), :class => "expand_likes"
- else
= link_to t('likes.likes.people_like_this', :count => likes_count), post_likes_path(target_id), :class => "expand_likes"
%span.hidden.likes_list

View file

@ -1,2 +1,3 @@
$(".like_action", "#<%=@like.target.guid%>").first().html("<%= escape_javascript(like_action(@like.target))%>");
ContentUpdater.addLikesToPost("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.reload.likes_count, :target_type => @like.target_type)) %>");
var targetGuid = "<%=@like.target.guid%>";
$(".like_action", "#"+targetGuid).first().html("<%= escape_javascript(like_action(@like.target))%>");
ContentUpdater.addLikesToPost(targetGuid, "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.reload.likes_count, :target_type => @like.target_type)) %>");

View file

@ -74,6 +74,7 @@
= link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea'
.likes.on_post
= render "likes/likes_container", :target_id => post.id, :likes_count => post.likes_count, :current_user => current_user, :target_type => "Post"
.likes_container
= render "likes/likes_container", :target_id => post.id, :likes_count => post.likes_count, :current_user => current_user, :target_type => "Post"
= render "comments/comments", :post => post, :current_user => current_user, :commenting_disabled => @commenting_disabled

View file

@ -16,7 +16,7 @@ var ContentUpdater = {
streamElement.prependTo("#main_stream:not('.show')").fadeIn("fast", function() {
streamElement.find("label").inFieldLabels();
});
Diaspora.page.stream.addPost(streamElement);
Diaspora.page.publish("stream/postAdded", [postGUID]);
}
},
@ -51,10 +51,7 @@ var ContentUpdater = {
.fadeOut("fast")
.html(html);
Diaspora.page
.stream
.streamElements[postGUID]
.likes.publish("widget/ready", [likesContainer]);
Diaspora.page.publish("likes/" + postGUID + "/updated");
likesContainer.fadeIn("fast");
}

View file

@ -61,6 +61,7 @@
$.extend(this, {
backToTop: this.instantiate("BackToTop", body.find("#back-to-top")),
directionDetector: this.instantiate("DirectionDetector"),
events: function() { return Diaspora.page.eventsContainer.data("events"); },
flashMessages: this.instantiate("FlashMessages"),
header: this.instantiate("Header", body.find("header")),
hoverCard: this.instantiate("HoverCard", body.find("#hovercard"))

View file

@ -13,13 +13,17 @@
self.deleteCommentLink.click(self.removeComment);
self.deleteCommentLink.tipsy({ trigger: "hover" });
self.content.expander({
slicePoint: 200,
widow: 18,
expandText: Diaspora.I18n.t("show_more"),
userCollapse: false
});
self.globalSubscribe("likes/" + self.comment.attr('id') + "/updated", function(){
self.likes = self.instantiate("Likes", self.comment.find(".likes_container"));
});
});
this.removeComment = function(evt) {

View file

@ -15,6 +15,7 @@
this.expandLikes = function(evt) {
evt.preventDefault();
console.log("called again");
if(self.likesList.children().length == 0) {
self.loadingImage.appendTo(self.likesContainer);
@ -33,4 +34,4 @@
};
Diaspora.Widgets.Likes = Likes;
})();
})();

View file

@ -18,6 +18,7 @@
focusCommentLink: element.find("a.focus_comment_textarea"),
hidePostLoader: element.find("img.hide_loader"),
hidePostUndo: element.find("a.stream_element_hide_undo"),
post: element,
postScope: element.find("span.post_scope")
});
@ -33,6 +34,10 @@
userCollapse: false
});
self.globalSubscribe("likes/" + self.postGuid + "/updated", function() {
self.likes = self.instantiate("Likes", self.post.find(".likes_container:first"));
});
self.deletePostLink.click(function(evt) {
evt.preventDefault();