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; if( elButton.childElementCount!=1 || elButton.firstChild.tagName!="SPAN" ){ while( elButton.firstChild ) elButton.removeChild(elButton.lastChild); elButton.appendChild(document.createElement("span")); } return elButton; } setTimeout(function(){ var elButtons = document.getElementsByClassName("copy-button"); for ( var i=0; i0 ){ text = text.slice(0,cchLength); } copyTextToClipboard(text); } } function copyTextToClipboard(text){ if( window.clipboardData && window.clipboardData.setData ){ window.clipboardData.setData("Text",text); }else{ var elTextarea = document.createElement("textarea"); elTextarea.style.position = "fixed"; elTextarea.value = text; document.body.appendChild(elTextarea); elTextarea.select(); try{ document.execCommand("copy"); }catch(err){ }finally{ document.body.removeChild(elTextarea); } } }