From b8529b7920e55575e12fb6a9d01ebfcc82922fc0 Mon Sep 17 00:00:00 2001 From: Jerome Jutteau Date: Sun, 9 Jul 2017 16:48:32 +0200 Subject: [PATCH] [FEATURE] Add a copy button next to links closes #129 Signed-off-by: Jerome Jutteau --- index.php | 25 ++++++++++++++++++++----- lib/functions.js.php | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) 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);}); +} -- 2.34.1