X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/75c98902b1f1be9a4cd1429886c3089c568e532b..b8529b7920e55575e12fb6a9d01ebfcc82922fc0:/lib/functions.js.php diff --git a/lib/functions.js.php b/lib/functions.js.php index 542000b..6ee335d 100644 --- a/lib/functions.js.php +++ b/lib/functions.js.php @@ -710,3 +710,25 @@ document.addEventListener('DOMContentLoaded', function(event) { // Search for all datetime fields and convert the time to local timezone convertAllDatetimeFields(); }); + +// Add copy event listeners +function copyLinkToClipboard(link_id) { + var focus = document.activeElement; + var e = document.getElementById(link_id); + + var tmp = document.createElement("textarea"); + document.body.appendChild(tmp); + tmp.textContent = e.href; + tmp.focus(); + tmp.setSelectionRange(0, tmp.value.length); + document.execCommand("copy"); + document.body.removeChild(tmp); + + focus.focus(); +} + +function addCopyListener(button_id, link_id) { + document.getElementById(button_id) + .addEventListener("click", function() { + copyLinkToClipboard(link_id);}); +}