Скроллить к добавленному комментарию на странице поста

This commit is contained in:
isqua 2015-02-07 20:11:23 +03:00
parent 62e20aca51
commit 00846a56cc

View file

@ -165,15 +165,7 @@ AjaxCommentProcessor.prototype.onSuccess = function(data, textStatus) {
if (data.error) {
this.onError(null, null, data.error);
} else {
// Creating the comment HTML
create_comment_elements({
id: data.comment_id,
toId: this._commentId || null,
postId: this._postId,
author: $('#name h1').text(),
text: this._text,
fadeOut: true
}, this.insertComment.bind(this));
this.createComment(data);
this.hideForm();
@ -184,6 +176,17 @@ AjaxCommentProcessor.prototype.onSuccess = function(data, textStatus) {
}
};
AjaxCommentProcessor.prototype.createComment = function(data) {
create_comment_elements({
id: data.comment_id,
toId: this._commentId || null,
postId: this._postId,
author: $('#name h1').text(),
text: this._text,
fadeOut: true
}, this.insertComment.bind(this));
};
/**
* Вставляет комментарий в DOM
* @param {jQuery} $comment
@ -212,6 +215,14 @@ AjaxCommentProcessor.prototype.insertComment = function($comment) {
);
}
}
this.showComment($comment);
};
AjaxCommentProcessor.prototype.showComment = function($comment) {
$('body').animate({
scrollTop: $comment.offset().top
}, 500);
};
/**