Copy-to-Clipboard on a DOM element
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.
$ component install component/clipboard-dom
<!-- The "copy-button" *should* be inside a div with "position: relative"or something else that "has layout". -->Copy to Clipboard
// main.jsvar Clip = require'clipboard-dom';// set the path to the swf file firstClipswf'/swf/ZeroClipboard.swf';// create a "Clip" instancevar ele = documentgetElementById'copy-button';var parent = eleparentNode; // parent should "have layout"var clip = ele parent;// listen for meaningful eventsclipon'load'console.log'button loaded';;clipon'complete'console.log'copied text to the clipboard:' text;;clipon'mousedown'// "mousedown" is the last chance to set the text before it gets copiedvar input = documentgetElementById'copy-text';cliptextinputvalue;;
Fired when the SWF movie for the clipboard instance has loaded.
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.
Fired when the user mouses over the button.
Fired when the user mouses away from the button.
Fired when the user pressed the mouse down on the button.
Fired when the user releases the mouse from the button.