comments, forum posts: add 'Copy Link' action to '...' menu.
Add a 'Copy Link' action to forum posts and comments. This copies the full link to the clipboard. The 'Copy ID' action copies just the DText shortlink (comment #XXX or forum #XXX).
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
class ApplicationComponent < ViewComponent::Base
|
||||
delegate :link_to_user, :time_ago_in_words_tagged, :format_text, :external_link_to, :tag_class, to: :helpers
|
||||
delegate :edit_icon, :delete_icon, :undelete_icon, :flag_icon, :upvote_icon, :downvote_icon, :link_icon, :sticky_icon, :unsticky_icon, to: :helpers
|
||||
delegate :edit_icon, :delete_icon, :undelete_icon, :flag_icon, :upvote_icon, :downvote_icon, :link_icon, :sticky_icon, :unsticky_icon, :hashtag_icon, to: :helpers
|
||||
|
||||
def policy(subject)
|
||||
Pundit.policy!(current_user, subject)
|
||||
|
||||
@@ -132,9 +132,15 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% menu.item do %>
|
||||
<%= link_to comment_path(comment.id), class: "comment-copy-id" do %>
|
||||
<%= hashtag_icon %> Copy ID
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% menu.item do %>
|
||||
<%= link_to comment_path(comment.id), class: "comment-copy-link" do %>
|
||||
<%= link_icon %> Copy ID
|
||||
<%= link_icon %> Copy Link
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ class CommentComponent {
|
||||
$(document).on("click.danbooru.comment", ".edit_comment_link", CommentComponent.showEditForm);
|
||||
$(document).on("click.danbooru.comment", ".expand-comment-response", CommentComponent.showNewCommentForm);
|
||||
$(document).on("click.danbooru.comment", ".unhide-comment-link", CommentComponent.unhideComment);
|
||||
$(document).on("click.danbooru.comment", ".comment-copy-id", CommentComponent.copyID);
|
||||
$(document).on("click.danbooru.comment", ".comment-copy-link", CommentComponent.copyLink);
|
||||
}
|
||||
}
|
||||
@@ -30,17 +31,18 @@ class CommentComponent {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
static async copyLink(e) {
|
||||
let $comment = $(this).closest(".comment");
|
||||
let link = `comment #${$comment.data("id")}`;
|
||||
static async copyID(e) {
|
||||
let id = $(this).closest(".comment").data("id");
|
||||
let link = `comment #${id}`;
|
||||
Utility.copyToClipboard(link);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(link);
|
||||
Utility.notice(`Copied ${link} to clipboard.`);
|
||||
} catch (error) {
|
||||
Utility.error("Couldn't copy link to clipboard");
|
||||
}
|
||||
static async copyLink(e) {
|
||||
let id = $(this).closest(".comment").data("id");
|
||||
let link = `${window.location.origin}/comments/${id}`;
|
||||
Utility.copyToClipboard(link);
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +65,15 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% menu.item do %>
|
||||
<%= link_to forum_post_path(forum_post.id), class: "forum-post-copy-id" do %>
|
||||
<%= hashtag_icon %> Copy ID
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% menu.item do %>
|
||||
<%= link_to forum_post_path(forum_post.id), class: "forum-post-copy-link" do %>
|
||||
<%= link_icon %> Copy ID
|
||||
<%= link_icon %> Copy Link
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -6,6 +6,7 @@ class ForumPostComponent {
|
||||
$(document).on("click.danbooru.forum_post", ".edit_forum_post_link", ForumPostComponent.showEditPostForm);
|
||||
$(document).on("click.danbooru.forum_post", ".edit_forum_topic_link", ForumPostComponent.showEditTopicForm);
|
||||
$(document).on("click.danbooru.forum_post", "#new-response-link", ForumPostComponent.showNewForumPostForm);
|
||||
$(document).on("click.danbooru.forum_post", ".forum-post-copy-id", ForumPostComponent.copyID);
|
||||
$(document).on("click.danbooru.forum_post", ".forum-post-copy-link", ForumPostComponent.copyLink);
|
||||
}
|
||||
}
|
||||
@@ -26,17 +27,18 @@ class ForumPostComponent {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
static async copyLink(e) {
|
||||
let $forumPost = $(this).closest(".forum-post");
|
||||
let link = `forum #${$forumPost.data("id")}`;
|
||||
static async copyID(e) {
|
||||
let id = $(this).closest(".forum-post").data("id");
|
||||
let link = `forum #${id}`;
|
||||
Utility.copyToClipboard(link);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(link);
|
||||
Utility.notice(`Copied ${link} to clipboard.`);
|
||||
} catch (error) {
|
||||
Utility.error("Couldn't copy link to clipboard");
|
||||
}
|
||||
static async copyLink(e) {
|
||||
let id = $(this).closest(".forum-post").data("id");
|
||||
let link = `${window.location.origin}/forum_posts/${id}`;
|
||||
Utility.copyToClipboard(link);
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user