fix click to copy when there is more than one copy link on the page.

Fixes issue reported on the mailing list here: https://lists.archlinux.org/pipermail/aur-general/2022-March/036833.html

Thanks to Henry-Joseph Audéoud for diagnosing the issue
https://lists.archlinux.org/pipermail/aur-general/2022-March/036836.html

Also update the event variable to use the local copy instead of the
deprecated global version
https://stackoverflow.com/questions/58341832/event-is-deprecated-what-should-be-used-instead
This commit is contained in:
Matt Harrison 2022-03-07 12:37:54 -05:00
parent c7c79a152b
commit b80d914cba
No known key found for this signature in database
GPG key ID: D2C220A71DA3C135
3 changed files with 6 additions and 6 deletions

View file

@ -1,6 +1,6 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
document.querySelector('.copy').addEventListener('click', function(e) { document.querySelectorAll('.copy').addEventListener('click', function(e) {
e.preventDefault(); e.preventDefault();
navigator.clipboard.writeText(event.target.text); navigator.clipboard.writeText(e.target.text);
}); });
}); });

View file

@ -309,9 +309,9 @@ endif;
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
document.querySelector('.copy').addEventListener('click', function(e) { document.querySelectorAll('.copy').addEventListener('click', function(e) {
e.preventDefault(); e.preventDefault();
navigator.clipboard.writeText(event.target.text); navigator.clipboard.writeText(e.target.text);
}); });
}); });
</script> </script>

View file

@ -138,9 +138,9 @@ endif;
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
document.querySelector('.copy').addEventListener('click', function(e) { document.querySelectorAll('.copy').addEventListener('click', function(e) {
e.preventDefault(); e.preventDefault();
navigator.clipboard.writeText(event.target.text); navigator.clipboard.writeText(e.target.text);
}); });
}); });
</script> </script>