GithubHelp home page GithubHelp logo

anthrax3 / clipboard-dom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from component/clipboard-dom

0.0 1.0 0.0 230 KB

Makes a DOM element (i.e. <button>) write to the system clipboard

Home Page: http://component.github.io/clipboard-dom

Makefile 1.65% JavaScript 87.86% HTML 10.49%

clipboard-dom's Introduction

clipboard-dom

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". -->
    <div style="position: relative;">
      <button id="copy-button">Copy to Clipboard</button>
    </div>
    <script src="build/build.js"></script>
    <script src="main.js"></script>
  </body>
</html>
// main.js

var Clip = require('clipboard-dom');

// set the path to the swf file first
Clip.swf('/swf/ZeroClipboard.swf');

// create a "Clip" instance
var ele = document.getElementById('copy-button');
var parent = ele.parentNode; // parent should "have layout"
var clip = new Clip(ele, parent);

// listen for meaningful events
clip.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 copied
  var input = 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.

clipboard-dom's People

Contributors

dominicbarnes avatar forbeslindesay avatar ianstormtaylor avatar jonathanong avatar kelonye avatar matthewmueller avatar rauchg avatar tootallnate avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.