47e27b2c48dd214a92be605c2df765dfcac74658b8d00eab72d1fa6de88a45717ae138f4c6455cfa7d7b2bee7679bafe9f91cb771ea53fc22a3b12183baccf 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. ### WARNING
  2. **This `master` branch contains the `v2.x` codebase for ZeroClipboard! For the `v1.x` codebase, see the [`1.x-master`](https://github.com/zeroclipboard/zeroclipboard/tree/1.x-master) branch instead.**
  3. # ZeroClipboard
  4. [![GitHub Latest Release](https://badge.fury.io/gh/zeroclipboard%2Fzeroclipboard.svg)](https://github.com/zeroclipboard/zeroclipboard) [![Build Status](https://secure.travis-ci.org/zeroclipboard/zeroclipboard.svg?branch=master)](https://travis-ci.org/zeroclipboard/zeroclipboard) ![GZip Size](https://badge-size.herokuapp.com/zeroclipboard/zeroclipboard/master/dist/ZeroClipboard.min.js?compression=gzip) [![Coverage Status](https://coveralls.io/repos/zeroclipboard/zeroclipboard/badge.svg?branch=master)](https://coveralls.io/r/zeroclipboard/zeroclipboard?branch=master) [![Dependency Status](https://david-dm.org/zeroclipboard/zeroclipboard.svg?theme=shields.io)](https://david-dm.org/zeroclipboard/zeroclipboard) [![Dev Dependency Status](https://david-dm.org/zeroclipboard/zeroclipboard/dev-status.svg?theme=shields.io)](https://david-dm.org/zeroclipboard/zeroclipboard#info=devDependencies)
  5. The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible [Adobe Flash](http://en.wikipedia.org/wiki/Adobe_Flash) movie and a [JavaScript](http://en.wikipedia.org/wiki/JavaScript) interface. The "Zero" signifies that the library is invisible and the user interface is left entirely up to you.
  6. This is achieved by automatically floating the invisible movie on top of a [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) element of your choice. Standard mouse events are even propagated out to your DOM element, so you can still have rollover and mousedown effects.
  7. Suggestions welcome read over the [contributing](/CONTRIBUTING.md) guidelines.
  8. ## Setup
  9. To setup the project for local development start with these commands in your terminal.
  10. ```sh
  11. $ git clone https://github.com/zeroclipboard/zeroclipboard.git
  12. $ cd zeroclipboard/
  13. $ npm install -g grunt-cli
  14. $ npm install
  15. $ grunt
  16. ```
  17. ## Development
  18. Before submitting a pull request you'll need to validate, build, and test your code. Run the default grunt task in your terminal.
  19. ```sh
  20. $ grunt
  21. ```
  22. ## Testing
  23. If you just want to run the tests, run grunt test.
  24. ```sh
  25. $ grunt test
  26. ```
  27. ## Limitations
  28. ### User Interaction Required
  29. Due to browser and Flash security restrictions, this clipboard injection can _**ONLY**_ occur when
  30. the user clicks on the invisible Flash movie. A simulated `click` event from JavaScript will not
  31. suffice as this would enable [clipboard poisoning](http://www.computerworld.com/s/article/9117268/Adobe_patches_Flash_clickjacking_and_clipboard_poisoning_bugs).
  32. ### Other Limitations
  33. For a complete list of limitations, see [docs/instructions.md#limitations](docs/instructions.md#limitations).
  34. On that page, you will also find an [explanation of why ZeroClipboard will _NOT_ work by default on code playground sites](docs/instructions.md#starter-snippets-for-playground-sites) like JSFiddle, JSBin, and CodePen, as well as the appropriate "View" URLs to use on those sites in order to allow ZeroClipboard to work.
  35. ## Simple Example
  36. ```html
  37. <html>
  38. <body>
  39. <button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">Copy to Clipboard</button>
  40. <script src="ZeroClipboard.js"></script>
  41. <script src="main.js"></script>
  42. </body>
  43. </html>
  44. ```
  45. ```js
  46. // main.js
  47. var client = new ZeroClipboard( document.getElementById("copy-button") );
  48. client.on( "ready", function( readyEvent ) {
  49. // alert( "ZeroClipboard SWF is ready!" );
  50. client.on( "aftercopy", function( event ) {
  51. // `this` === `client`
  52. // `event.target` === the element that was clicked
  53. event.target.style.display = "none";
  54. alert("Copied text to clipboard: " + event.data["text/plain"] );
  55. } );
  56. } );
  57. ```
  58. See [docs/instructions.md](docs/instructions.md) for more advanced options in using the library on your site.
  59. See [docs/api/ZeroClipboard.md](docs/api/ZeroClipboard.md) for the complete API documentation.
  60. Here is a working [test page](http://zeroclipboard.org/#demo) where you can try out ZeroClipboard in your browser.
  61. ## Testing ZeroClipboard Locally
  62. To test the page [demo page](http://zeroclipboard.org/#demo) locally, clone the [website repo](https://github.com/zeroclipboard/zeroclipboard.org).
  63. ## Support
  64. This library is fully compatible with Flash Player 11.0.0 and above, which requires
  65. that the clipboard copy operation be initiated by a user click event inside the
  66. Flash movie. This is achieved by automatically floating the invisible movie on top
  67. of a [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) element of your
  68. choice. Standard mouse events are even propagated out to your DOM element, so you
  69. can still have rollover and mousedown effects with just a _little_ extra effort.
  70. ZeroClipboard `v2.x` is expected to work in IE9+ and all of the evergreen browsers.
  71. Although support for IE7 & IE8 was officially dropped in `v2.0.0`, it was actually
  72. still _technically_ supported through `v2.0.2`.
  73. ## Releases
  74. Starting with version [1.1.7](https://github.com/zeroclipboard/zeroclipboard/releases/tag/v1.1.7), ZeroClipboard uses [semantic versioning](http://semver.org/).
  75. see [releases](https://github.com/zeroclipboard/zeroclipboard/releases)
  76. ## Related
  77. * [jquery.zeroclipboard](https://github.com/zeroclipboard/jquery.zeroclipboard)
  78. * [zeroclipboard-rails](https://github.com/zeroclipboard/zeroclipboard-rails)
  79. ## License
  80. MIT &copy; [James M. Greene](http://greene.io/) [Jon Rohan](http://jonrohan.codes)