You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Makes a DOM element (i.e. <button>) write to the system clipboard. This
component is based off of the ZeroClipboard
project, and in fact uses the same SWF Flash code.
Installation
$ component install component/clipboard-dom
Example
<html><body><!-- The "copy-button" *should* be inside a div with "position: relative" or something else that "has layout". --><divstyle="position: relative;"><buttonid="copy-button">Copy to Clipboard</button></div><scriptsrc="build/build.js"></script><scriptsrc="main.js"></script></body></html>
// main.jsvarClip=require('clipboard-dom');// set the path to the swf file firstClip.swf('/swf/ZeroClipboard.swf');// create a "Clip" instancevarele=document.getElementById('copy-button');varparent=ele.parentNode;// parent should "have layout"varclip=newClip(ele,parent);// listen for meaningful eventsclip.on('load',function(){console.log('button loaded');});clip.on('complete',function(text){console.log('copied text to the clipboard:',text);});clip.on('mousedown',function(){// "mousedown" is the last chance to set the text before it gets copiedvarinput=document.getElementById('copy-text');clip.text(input.value);});
Events
"load"
Fired when the SWF movie for the clipboard instance has loaded.
"complete"
Fired when the user clicks on the button and the text has been copied.
The text that got copied is passed in as an argument.
"mouseover"
Fired when the user mouses over the button.
"mouseout"
Fired when the user mouses away from the button.
"mousedown"
Fired when the user pressed the mouse down on the button.
"mouseup"
Fired when the user releases the mouse from the button.
About
Makes a DOM element (i.e. <button>) write to the system clipboard