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:
@@ -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