]> git.p6c8.net - jirafeau_project.git/blobdiff - lib/functions.js.php
[FEATURE] Add a copy button next to links
[jirafeau_project.git] / lib / functions.js.php
index 542000b6574a96e04a1e92a8da3daa572492caa5..6ee335dacdcb3099dac6ca0a7f4fdfdd4740cc63 100644 (file)
@@ -710,3 +710,25 @@ document.addEventListener('DOMContentLoaded', function(event) {
     // Search for all datetime fields and convert the time to local timezone
     convertAllDatetimeFields();
 });
     // 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);});
+}

patrick-canterino.de