Overview
This is a simple theme component that adds a Copy button to the post menu control section of every post. Clicking the button will copy the entire contents of the post to the user’s clipboard.
Code
Preview
Install Theme Component
This is a simple theme component that adds a Copy button to the post menu control section of every post. Clicking the button will copy the entire contents of the post to the user’s clipboard.
Install Theme Component
Great theme component! Thanks
What happens to formatting and media?
May need to make some improvements in this area but currently:
<p>
tags will be present.Hope this can be updated to include media and formatting when pasted in Discourse.
Yes, definitely something I’ll be looking to improve in the future.
However, in the meantime, I’ve added a setting to copy the raw HTML content instead. If you set this to true, the copy button will copy the raw HTML of the post instead of the plain text. This way you should have the formatting and media.
Super!
Maybe a second button, Duplicate, (in the moderator gear icon area?) to automatically copy the entire contents of the post into a new topic with "DUPLICATE: " appended to the beginning of the title?
Anyway, very handy as is, thanks!
Maybe make the button do a request to /raw/topic_id/post_number
so you can copy the real post content? This way it will act like the very useful Reddit Enhancement Suite “Source” button.
Similar component already exists: Raw Post Button.
Adding a copy button to the modal of that component would combine both approaches, what do you think @keegan @Johani?
@md-misko Yup I think that’s a great idea. Since I created a widget for the copy button, I believe it can be quite simply copied over to be used in the modal.
Is there any trick to show the button to logged in users only?
There is now! I’ve added a setting to apply a minimum trust level to show the widget. Configuring it to 0
will make it so only logged in users can see the button.
Why can’t we put two thumbs up when it is earned
Now @keegan has them.
This wasn’t working on a new install.
The min_trust_level wasn’t selectable in Admin.
edit: component was functioning but wasn’t displaying correctly in Admin
I forked the repo and got it working but I set min_trust_level as an integer
So (5) = ‘disabled’ (0-4) as expected. So a small rewrite.
I haven’t done a PR … as it’s a simplification … perhaps someone else can confirm the component isn’t working?
Hey @geoff777 I’ve tested this on a new install and it seems to be working correctly for me.
Also if I do apply those changes, the issue with using setting the min_trust_level as an integer in the settings.yml file is that the 0 value isn’t appearing in the dropdown.
Any of values, except disabled, isn’t appearing in the box when selected. AFAIK any of values is in use, though.
Ah sorry, my mistake, I thought you meant you changed the strings in the enum to integers, but you meant you used the integer type instead. Yes, that seems like a better approach. I’ve updated the theme component to support that. Hopefully this should fix any of the issues.
This is a great TC! In our use case we want our authors to copy full posts and paste them into an external editor of a course website. It would be great if you could copy the whole post including media in HTML or just rich text format.