X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/75c98902b1f1be9a4cd1429886c3089c568e532b..5efae52e3028850bd88ed03945f5d912420a36d3:/lib/functions.js.php?ds=inline 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);}); +}