diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 92a39c61e..5714fcbab 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,5 +1,6 @@ class CommentsController < ApplicationController respond_to :html, :xml, :json + respond_to :js, only: [:new, :destroy, :undelete] before_action :member_only, :except => [:index, :search, :show] skip_before_action :api_check @@ -17,7 +18,9 @@ class CommentsController < ApplicationController end def new - redirect_to comments_path + @comment = Comment.new(comment_params(:create)) + @comment.body = Comment.find(params[:id]).quoted_response if params[:id] + respond_with(@comment) end def update @@ -45,25 +48,21 @@ class CommentsController < ApplicationController def show @comment = Comment.find(params[:id]) - respond_with(@comment, methods: [:quoted_response]) + respond_with(@comment) end def destroy @comment = Comment.find(params[:id]) check_privilege(@comment) @comment.delete! - respond_with(@comment) do |format| - format.js - end + respond_with(@comment) end def undelete @comment = Comment.find(params[:id]) check_privilege(@comment) @comment.undelete! - respond_with(@comment) do |format| - format.js - end + respond_with(@comment) end private diff --git a/app/javascript/src/javascripts/comments.js b/app/javascript/src/javascripts/comments.js index 50ad6a19a..aad19b7ca 100644 --- a/app/javascript/src/javascripts/comments.js +++ b/app/javascript/src/javascripts/comments.js @@ -2,31 +2,11 @@ let Comment = {}; Comment.initialize_all = function() { if ($("#c-posts").length || $("#c-comments").length) { - $(document).on("click.danbooru.comment", ".reply-link", Comment.quote); $(document).on("click.danbooru.comment", ".edit_comment_link", Comment.show_edit_form); $(document).on("click.danbooru.comment", ".expand-comment-response", Comment.show_new_comment_form); } } -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").find(".new-comment"); - var $textarea = $div.find("textarea"); - var msg = data.quoted_response; - if ($textarea.val().length > 0) { - msg = $textarea.val() + "\n\n" + msg; - } - $textarea.val(msg); - $div.find("a.expand-comment-response").trigger("click"); - $textarea.selectEnd(); - } - ); - e.preventDefault(); -} - Comment.show_new_comment_form = function(e) { $(e.target).hide(); var $form = $(e.target).closest("div.new-comment").find("form"); @@ -45,4 +25,3 @@ $(document).ready(function() { }); export default Comment - diff --git a/app/views/comments/new.js.erb b/app/views/comments/new.js.erb new file mode 100644 index 000000000..95648fdab --- /dev/null +++ b/app/views/comments/new.js.erb @@ -0,0 +1,11 @@ +var $div = $('div.comments-for-post[data-post-id="<%= @comment.post_id %>"] div.new-comment'); +$div.find(".expand-comment-response").click(); + +var $textarea = $div.find("textarea"); +var msg = "<%= j @comment.body %>"; +if ($textarea.val().length > 0) { + msg = $textarea.val() + "\n\n" + msg; +} + +$textarea.val(msg); +$textarea.selectEnd(); diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index d8f014098..ebf40b634 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -24,7 +24,7 @@ <% if CurrentUser.is_member? %>