wp-duckbehaviorjournal/assets/js/clipboard.js
Kumi 3bd51e66ed
feat: add DOI copy-to-clipboard functionality
Introduced a new JavaScript file to handle the DOI copy-to-clipboard feature. Updated the 'single-article.php' template to include a clickable DOI link that copies the DOI to the clipboard and displays a confirmation message. Enhances user convenience by simplifying the process of copying DOIs.
2024-06-20 15:24:22 +02:00

22 lines
705 B
JavaScript

document.addEventListener("DOMContentLoaded", function () {
const doiLink = document.getElementById("doi-link");
const doiCopyMessage = document.getElementById("doi-copy-message");
doiLink.addEventListener("click", function (event) {
event.preventDefault();
const doi = doiLink.getAttribute("data-doi");
const fullDoiUrl = `${window.location.origin}/${doi}`;
navigator.clipboard.writeText(fullDoiUrl).then(
function () {
doiCopyMessage.style.display = "inline";
setTimeout(function () {
doiCopyMessage.style.display = "none";
}, 2000);
},
function () {
alert("Failed to copy DOI to clipboard.");
}
);
});
});