From: Jerome Jutteau Date: Sun, 9 Jul 2017 14:48:32 +0000 (+0200) Subject: [FEATURE] Add a copy button next to links X-Git-Tag: 3.3.0~10 X-Git-Url: https://git.p6c8.net/jirafeau.git/commitdiff_plain/b8529b7920e55575e12fb6a9d01ebfcc82922fc0?hp=75c98902b1f1be9a4cd1429886c3089c568e532b [FEATURE] Add a copy button next to links closes #129 Signed-off-by: Jerome Jutteau --- diff --git a/index.php b/index.php index cd0eed8..11205a4 100644 --- a/index.php +++ b/index.php @@ -98,25 +98,35 @@ else {

- - + + +

-

+

+ + +

-

+

+ + +

-

+

+ + +

@@ -262,5 +272,10 @@ else { document.getElementById('max_file_size').innerHTML = ''; + + addCopyListener('upload_link_button', 'upload_link'); + addCopyListener('preview_link_button', 'preview_link'); + addCopyListener('direct_link_button', 'direct_link'); + addCopyListener('delete_link_button', 'delete_link'); 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);}); +}