diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 4ebd8e369..933faa522 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -6,6 +6,7 @@ this.initialize_response_link(); this.initialize_reply_links(); this.initialize_expand_links(); + this.initialize_edit_links(); } if ($("#c-posts").length && $("#a-show").length) { @@ -63,6 +64,16 @@ $("div.new-comment form").hide(); } + Danbooru.Comment.initialize_edit_links = function() { + $(".edit_comment").hide(); + $(".edit_comment_link").click(function(e) { + var link_id = $(this).attr("id"); + var comment_id = link_id.match(/^edit_comment_link_(\d+)$/)[1]; + $("#edit_comment_" + comment_id).toggle(); + e.preventDefault(); + }); + } + 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 + "]"); diff --git a/app/views/comments/_edit.html.erb b/app/views/comments/_edit.html.erb new file mode 100644 index 000000000..47b6e8698 --- /dev/null +++ b/app/views/comments/_edit.html.erb @@ -0,0 +1,5 @@ +<%= simple_form_for(comment) do |f| %> + <%= dtext_field "comment", "body", :value => comment.body, :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> + <%= f.button :submit, "Submit" %> + <%= dtext_preview_button "comment", "body", :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> +<% end %> diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 208dd5b0e..c6a90ec1a 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -20,12 +20,15 @@
  • <%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %>
  • <% if comment.editable_by?(CurrentUser.user) %>
  • <%= link_to "Delete", comment_path(comment.id), :confirm => "Are you sure you want to delete this comment?", :method => :delete, :remote => true %>
  • -
  • <%= link_to "Edit", edit_comment_path(comment.id) %>
  • +
  • <%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %>
  • <% end %> <% end %> + <% if comment.editable_by?(CurrentUser.user) %> + <%= render "comments/edit", :comment => comment %> + <% end %> <% end %>