diff --git a/assets/js/app.js b/assets/js/app.js index 579f6b4c..dd795052 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -272,6 +272,25 @@ topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) window.addEventListener("phx:page-loading-start", _info => topbar.show(300)) window.addEventListener("phx:page-loading-stop", _info => topbar.hide()) +// Handle clipboard copy events +window.addEventListener("phx:copy", (event) => { + const el = event.target + let text = "" + + if (el.tagName === "INPUT" || el.tagName === "TEXTAREA") { + text = el.value + } else { + text = el.innerText || el.textContent + } + + navigator.clipboard.writeText(text).then(() => { + // Optional: Show a success message or visual feedback + console.log('Copied to clipboard') + }).catch(err => { + console.error('Failed to copy text: ', err) + }) +}) + // connect if there are any LiveViews on the page liveSocket.connect()