fixed comment quoting
This commit is contained in:
@@ -6,6 +6,31 @@
|
|||||||
this.initialize_response_link();
|
this.initialize_response_link();
|
||||||
this.initialize_preview_button();
|
this.initialize_preview_button();
|
||||||
this.hide_threshold_comments();
|
this.hide_threshold_comments();
|
||||||
|
this.initialize_reply_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_response_link = function() {
|
Danbooru.Comment.initialize_response_link = function() {
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ class CommentsController < ApplicationController
|
|||||||
respond_with(@comment)
|
respond_with(@comment)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@comment = Comment.find(params[:id])
|
||||||
|
respond_with(@comment) do |format|
|
||||||
|
format.json {render :json => @comment.to_json(:methods => [:creator_name])}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def index_for_post
|
def index_for_post
|
||||||
@post = Post.find(params[:post_id])
|
@post = Post.find(params[:post_id])
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ class Comment < ActiveRecord::Base
|
|||||||
decrement!(:score)
|
decrement!(:score)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def creator_name
|
||||||
|
creator.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Comment.connection.extend(PostgresExtensions)
|
Comment.connection.extend(PostgresExtensions)
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div>
|
<div class="body">
|
||||||
<%= format_text(comment.body) %>
|
<%= format_text(comment.body) %>
|
||||||
</div>
|
</div>
|
||||||
<menu>
|
<menu>
|
||||||
<li><span class="link">Reply</span></li>
|
<li><%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %></li>
|
||||||
<% if CurrentUser.user.is_janitor? || CurrentUser.user.id == comment.creator_id %>
|
<% if CurrentUser.user.is_janitor? || CurrentUser.user.id == comment.creator_id %>
|
||||||
<li><%= link_to "Delete", comment_path(comment.id), :confirm => "Do you really want to delete this comment?", :method => :delete %></li>
|
<li><%= link_to "Delete", comment_path(comment.id), :confirm => "Do you really want to delete this comment?", :method => :delete %></li>
|
||||||
<li><%= link_to "Edit", edit_comment_path(comment.id) %></li>
|
<li><%= link_to "Edit", edit_comment_path(comment.id) %></li>
|
||||||
|
|||||||
Reference in New Issue
Block a user