summaryrefslogtreecommitdiff
path: root/js/copy.js
diff options
context:
space:
mode:
authordweller <dweller@cabin.digital>2024-02-26 11:47:32 +0200
committerdweller <dweller@cabin.digital>2024-02-26 11:47:32 +0200
commitf0181813ecf9867f13a206d87fc46b15d295acbc (patch)
treeb1b6f94e6a2318010cb322bbd119356b46076dd4 /js/copy.js
parenta87359aaacac66655af6baa80ced112ac842f651 (diff)
wire up frontend with PHP, badly
Diffstat (limited to '')
-rw-r--r--js/copy.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/js/copy.js b/js/copy.js
new file mode 100644
index 0000000..3bc7707
--- /dev/null
+++ b/js/copy.js
@@ -0,0 +1,32 @@
+const dom_lmmtfy = document.getElementById("lmmtfy_url");
+const dom_copy = document.getElementById("lmmtfy_copy");
+
+dom_copy.onclick = lmmtfy_copy;
+
+function lmmtfy_copy()
+{
+ dom_lmmtfy.focus();
+ dom_lmmtfy.select();
+
+ try
+ {
+ // TODO: deprecated -- https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
+ if(document.execCommand('copy'))
+ dom_copy.innerHTML = "Copied!"
+
+ setTimeout(() =>
+ {
+ dom_copy.innerHTML = "Copy"
+ }, 3000);
+
+ }
+ catch(err)
+ {
+ dom_copy.innerHTML = "Error :(";
+ console.log('Oops, unable to copy');
+ }
+
+ // This unfocuses the element, but W3C decided to be funny with
+ // the naming.
+ document.activeElement.blur();
+}