Skip to content

Commit

Permalink
Add copy link button
Browse files Browse the repository at this point in the history
  • Loading branch information
murdo-moj committed Nov 22, 2024
1 parent 251f83f commit 9a7ecb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions static/assets/js/copy-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
document.addEventListener('DOMContentLoaded', () => {
const copyButton = document.getElementById('copyButton');
if (copyButton) {
copyButton.addEventListener('click', () => {
const linkToCopy = window.location.href; // Or any specific link
navigator.clipboard.writeText(linkToCopy)
.then(() => {
// Change button text
copyButton.innerText = 'Link Copied';
copyButton.disabled = true; // Optional: Disable button to prevent repeated clicks
setTimeout(() => {
copyButton.innerText = 'Copy Link'; // Reset text after 3 seconds
copyButton.disabled = false;
}, 3000);
})
.catch(err => console.error('Failed to copy: ', err));
});
}
});
7 changes: 7 additions & 0 deletions templates/details_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ <h2 class="govuk-heading-s govuk-!-margin-top-3">
</div>
{% block extra_description %}
{% endblock extra_description %}
<button id="copyButton" class="govuk-button govuk-button--secondary">
Copy link
</button>
{% block metadata_list %}
<ul class="govuk-list govuk-body" id="metadata-property-list">
{% if entity.created %}
Expand Down Expand Up @@ -120,3 +123,7 @@ <h2 class="govuk-heading-s govuk-!-margin-top-3">
{% block extra_details %}
{% endblock extra_details %}
{% endblock content %}

{% block scripts %}
<script src="{% static 'assets/js/copy-button.js' %}"></script>
{% endblock scripts %}

0 comments on commit 9a7ecb7

Please sign in to comment.