From 4f49b16079b27d7ce633619e4cddfdf2bffbc952 Mon Sep 17 00:00:00 2001 From: cashmere Date: Fri, 4 Sep 2026 09:05:24 +0200 Subject: initial commit --- src/copybtn.js | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/copybtn.js (limited to 'src/copybtn.js') diff --git a/src/copybtn.js b/src/copybtn.js new file mode 100644 index 0000000..869e318 --- /dev/null +++ b/src/copybtn.js @@ -0,0 +1,99 @@ +/* Manage "Copy Buttons" linked to target elements, to copy the text (or, parts +** thereof) of the target elements to the clipboard. +** +** Newly created buttons are +*/ +function makeCopyButton(idTarget,bFlipped,cchLength){ + var elButton = document.createElement("button"); + elButton.className = "copy-button"; + if( bFlipped ) elButton.className += " copy-button-flipped"; + elButton.id = "copy-" + idTarget; + initCopyButton(elButton,idTarget,cchLength); + return elButton; +} +function initCopyButtonById(idButton,idTarget,cchLength){ + idButton = idButton || "copy-" + idTarget; + var elButton = document.getElementById(idButton); + if( elButton ) initCopyButton(elButton,idTarget,cchLength); + return elButton; +} +function initCopyButton(elButton,idTarget,cchLength){ + if( idTarget ) elButton.setAttribute("data-copytarget",idTarget); + if( cchLength ) elButton.setAttribute("data-copylength",cchLength); + elButton.onclick = clickCopyButton; + /* Make sure the