Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for copying to clipboard #4853

Open
koshka opened this issue Sep 7, 2016 · 28 comments
Open

Support for copying to clipboard #4853

koshka opened this issue Sep 7, 2016 · 28 comments

Comments

@koshka
Copy link
Contributor

koshka commented Sep 7, 2016

Description

Our pages allow users to copy the share URL, (in addition to basic social sharing). To allow our pages to support AMP, we need to be able to copy content to clipboard without JS.

Current feature is provided by a 3rd party tool clipboardjs. We cannot find equivalent functionality.

Example

https://gfycat.com/BareSecondaryFlamingo
Click on the embed </> button below the video
Click on the copy to clipboard icon

@jridgewell
Copy link
Contributor

This would be great, as long as we don't do the spammy text-selection hijacking.

@cramforce
Copy link
Member

Would be a neat addition to amp-social-share.

@koshka Would you be interested in implementing this and contributing it to the project?

@ericlindley-g ericlindley-g added this to the Pending Triage milestone Sep 14, 2016
@rudygalfi rudygalfi removed their assignment Sep 26, 2016
@torch2424
Copy link
Contributor

Hello! As per the Contributing Guidelines I'd like to show an "intent to implement", a Pull request for this issue.

I plan on using something like: https://www.sitepoint.com/javascript-copy-to-clipboard/ , and clipboard.js for any other reference 😄

I agree with @jridgewell, and try to make the component specifically display the text that will be copied.

@jridgewell
Copy link
Contributor

@torch2424: That'd be lovely.

@cramforce
Copy link
Member

I wonder if requiring the show the URL is a little too opinionated. Awesome you are working on this @torch2424!!

@torch2424
Copy link
Contributor

Just Finished this. Probably have a PR opened in today, or within the next week. Currently wrapping up the validator, and some Docs

@sohanirao
Copy link
Contributor

It was concluded that due to lack of cross browser support, this is infeasible. Should not be a GFI candidate anymroe.

@taymonbeal
Copy link
Member

<amp-story> supports this. Given that, is there any reason <amp-social-share> can't?

@cramforce
Copy link
Member

cramforce commented Mar 29, 2018 via email

@samthor
Copy link

samthor commented Jul 25, 2018

As a drive-by comment: we implement this with an amp-iframe that just loads a tiny page containing a copy button with regular JS. We have a placeholder button in the top-level page, which is almost immediately replaced with the iframe.

@torch2424
Copy link
Contributor

torch2424 commented Oct 16, 2018

Just wanted to bump this a little bit, totally forgot, but @sebastianbenz and I discussed how this would be really helpful for AMP By Example, and the upcoming amp.dev at the contributor summit. Would be cool if we could get something going on this, especially since a lot of issues I had with my original PR, are now fixed in later versions of mobile safari (i think) 😄

@samthor
Copy link

samthor commented Oct 16, 2018

Here's the iframe solution: https://ampbyexample.com/advanced/copy_button/preview/

@torch2424
Copy link
Contributor

@samthor Thank you for this! Great that we have a link in the issue in case someone else comes across this 👍

@sebastianbenz
Copy link
Contributor

sebastianbenz commented Oct 26, 2018

For amp.dev it'd be great to have the ability to copy code snippets from the documentation samples. For this case It'd be great to have a simple copy action which specifies a node and recursively concatenates all child text nodes to a single string which is then added to the clipboard:

<button on="tap:mySnippet.copyToClipboard">
<pre id="mySnippet">
Code ...
</pre>

@sebastianbenz
Copy link
Contributor

Hey @torch2424 are there any updates on this? It'd be really fantastic to have this available for amp.dev.

@torch2424
Copy link
Contributor

@sebastianbenz My apologies! Wasn't sure if the iframe solution would suffice or not. I will pass this around the team in mountain view, and see if we can get some traction on this 👍

@rudygalfi
Copy link
Contributor

cc @nainar - can you investigate prioritization?

@torch2424
Copy link
Contributor

I'll let @nainar investigate/prioritize this. Feel free to reach out to me on this topic, I actually made an extension for this about a year and a half ago, so before we start implementation perhaps we can possibly re-use some of that code (probably not though).

Thanks for catching this @rudygalfi ! 😄

@catherinehoule
Copy link
Contributor

@aghassemi You marked this "soon" about 6 months ago. Is there any plans to work on it ? Thank you !

@aghassemi
Copy link
Contributor

Hi @catherinehoule, would the solution outlined on https://ampbyexample.com/advanced/copy_button/preview/ work for you and unblock you?

@catherinehoule
Copy link
Contributor

@aghassemi That works but feels a bit hacky... I was wondering if there was plans to make this issue happening since it's been sitting in soon state for a while. Thanks for the quick answer !

@catherinehoule
Copy link
Contributor

catherinehoule commented Mar 3, 2020

@aghassemi Would you happen to have a solution that works with a screen reader using the arrows.
On mac, it works using the tab to navigate thru button in the example then click but still screen readers users uses arrow to read documents. And on PC I've been told that it doesn't work at all.
(I tried adding keypressed to the onclick)

@shishirraven
Copy link

Using Iframe for copy seems to be a overkill.
For me I just needed a button to allow users to copy Email ID,
Just to make it easier. But including Iframe Javascript will make the page heavier.

What is the best solution?

@westonruter
Copy link
Member

Just came across this. I have a WordPress plugin for adding syntax highlighting to code blocks (which is used on blog.amp.dev). Various users have asked for a Copy to Clipboard button to go next to the code block: westonruter/syntax-highlighting-code-block#192

But this is blocked by not having the capability in AMP.

@mhdfasilwyd
Copy link

Any updates?

@stale
Copy link

stale bot commented Jan 22, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Jan 22, 2023
@NicoHood
Copy link

Will this still get implemented?

@stale stale bot removed the Stale Inactive for one year or more label Feb 21, 2023
@bantilan
Copy link

bantilan commented Aug 22, 2023

Just an update to those who are searching for clipboard function - since it's hard to find answer in the internet, you can use the copy(), copy-success and copy-error:

example code:

<button on="tap:inputTarget.copy();copy-success:inputCopySuccess.show();copy-error:inputCopyError.show()">Copy</button>

tap:input_id_to_copy.copy(); Use this to specify the input you want to copy. For example:
<input id="inputTarget" value="Sample Input Value" />

copy-success:element_id_to_show_for_success.show(); Utilize this to display a success message when the value is copied successfully. Example:
<span id="inputCopySuccess" hidden class="copy-success">Value copied successfully!</span>

copy-error:element_id_to_show_for_error.show(); Apply this function to show an error message if the copying fails. For instance:
<span id="inputCopyError" hidden class="copy-error">Error while copying!</span>

or simply use this one:

tap:AMP.copy(text='Hello AMP!');copy-success:staticTextCopySuccess.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.