Files
danbooru/app/assets/javascripts/comments.js
albert c478eb33b6 * Additional effects
* Fixed flash pngs
* Fixed dmail search links
2011-11-03 17:42:40 -04:00

71 lines
2.2 KiB
JavaScript

(function() {
Danbooru.Comment = {};
Danbooru.Comment.initialize_all = function() {
if ($("#c-posts").length || $("#c-comments").length) {
this.initialize_response_link();
this.initialize_reply_links();
this.initialize_expand_links();
}
}
Danbooru.Comment.quote_message = function(data) {
var stripped_body = data["body"].replace(/\[quote\](?:.|\n|\r)+?\[\/quote\](?:\r\n|\r|\n)*/gm, "");
return "[quote]\n" + data["creator_name"] + " said:\n" + stripped_body + "\n[/quote]\n\n";
}
Danbooru.Comment.quote = function(e) {
$.get(
"/comments/" + $(e.target).data('comment-id') + ".json",
function(data) {
var $link = $(e.target);
var $div = $link.closest("div.comments-for-post");
var $textarea = $div.find("textarea")
$textarea.val(Danbooru.Comment.quote_message(data));
$div.find("a.expand-comment-response").trigger("click");
$textarea.focus();
}
);
e.preventDefault();
}
Danbooru.Comment.initialize_reply_links = function() {
$(".reply-link").click(Danbooru.Comment.quote);
}
Danbooru.Comment.initialize_expand_links = function() {
$(".comment-section form").hide();
$(".comment-section input.expand-comment-response").click(function(e) {
var post_id = $(this).closest(".comment-section").data("post-id");
$(this).hide();
$(".comment-section[data-post-id=" + post_id + "] form").slideDown("fast");
e.preventDefault();
});
}
Danbooru.Comment.initialize_response_link = function() {
$("a.expand-comment-response").click(function(e) {
$(e.target).hide();
$(e.target).closest("div.new-comment").find("form").slideDown("fast");
e.preventDefault();
});
$("div.new-comment form").hide();
}
Danbooru.Comment.highlight_threshold_comments = function(post_id) {
var threshold = parseInt(Danbooru.meta("user-comment-threshold"));
var articles = $("article.comment[data-post-id=" + post_id + "]");
articles.each(function(i, v) {
var $comment = $(v);
if (parseInt($comment.data("score")) < threshold) {
$comment.addClass("below-threshold");
}
})
}
})();
$(document).ready(function() {
Danbooru.Comment.initialize_all();
});