-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
added copy url button #8806
added copy url button #8806
Conversation
This seems to work though it's unclear to the patron whether the copying has succeeded. We either need some message or to show the text in a popup, like the "embed" option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some confirmation required (e.g. a toast message or popup) that the url copying succeeded
@jimchamp is this a good place to use toast? Do we have an example of doing this via js? |
Yes, and the modal should close when the URL copy icon is clicked. Will provide guidance shortly... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Ayush1404! Happy to merge this once the suggested changes have been made.
You may already be aware of this, but when any .less
or .js
file is modified, the CSS and JS assets must be recompiled. There is more information about this here.
Let me know if you have any questions about anything.
openlibrary/macros/ShareModal.html
Outdated
<a class="copy-url-btn" title="$_('Copy url to clipboard')" data-ol-link-track="Share|CopyURL" | ||
onclick="navigator.clipboard.writeText('openlibrary.org'+'$page_url');"> | ||
<img | ||
alt="CopyURL icon" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alt="CopyURL icon" | |
alt="$_('Copy URL icon')" |
Add space between Copy
and URL
. Use localized strings (more information about this here).
openlibrary/macros/ShareModal.html
Outdated
<a class="copy-url-btn" title="$_('Copy url to clipboard')" data-ol-link-track="Share|CopyURL" | ||
onclick="navigator.clipboard.writeText('openlibrary.org'+'$page_url');"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<a class="copy-url-btn" title="$_('Copy url to clipboard')" data-ol-link-track="Share|CopyURL" | |
onclick="navigator.clipboard.writeText('openlibrary.org'+'$page_url');"> | |
<a class="copy-url-btn" title="$_('Copy url to clipboard')" data-ol-link-track="Share|CopyURL"> |
Move inline JS to Webpack. To do so, you can update this function to do the following:
- Get a reference to the "Copy URL" icon. This query should work
#social-modal-content .copy-url-btn
. - Add a click listener to the icon.
The click listener should:
- Copy the URL to the clipboard.
- Close the modal. (Running
$.colorbox.close()
will achieve this) - Display a toast message that tells the patron that the message has been copied to their clipboard. You can use this function to display the toast message (only pass
message
---$parent
is not needed).
ad5aa7c
to
4722e3b
Compare
$('#social-modal-content .copy-url-btn').on('click', function(event){ | ||
event.preventDefault(); | ||
navigator.clipboard.writeText(window.location.href); | ||
showToast('URL copied successfully') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimchamp question, is there a way we handle i18n in JS like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'll include that in the follow-up issue (mentioned here).
Thanks for pointing that out. Let's consider this out of scope for this PR. As a follow-up, I'll open an issue for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Ayush1404!
I'm going to commit my small suggested changes, then merge this branch.
/** | ||
* Adds click listeners to buttons in all notes modals on a page. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* Adds click listeners to buttons in all notes modals on a page. | |
*/ | |
/** | |
* Adds click listener which copies the current page's URL to the clipboard. | |
*/ |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8806 +/- ##
==========================================
- Coverage 16.62% 16.02% -0.61%
==========================================
Files 88 89 +1
Lines 4698 4693 -5
Branches 838 818 -20
==========================================
- Hits 781 752 -29
- Misses 3399 3434 +35
+ Partials 518 507 -11 ☔ View full report in Codecov by Sentry. |
I ended up moving the inline |
Closes #8802
Adds way to copy the URL of the page you're on to share it.
Technical
Testing
Go to any books page and click on share.
Screenshot
Stakeholders
@mekarpeles