The Wayback Machine - https://web.archive.org/web/20190402062556/https://github.com/github/clipboard-copy-element
Skip to content
Copy element text content or input values to the clipboard.
Branch: master
Clone or download
Latest commit 0fa37fd Mar 29, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src clipboard-copied -> clipboard-copy Mar 28, 2019
test clipboard-copied -> clipboard-copy Mar 28, 2019
.eslintrc.json
.flowconfig
.gitignore
.travis.yml Add Travis configuration Apr 17, 2018
LICENSE
README.md
package-lock.json
package.json
prettier.config.js
rollup.config.js

README.md

<clipboard-copy> element

Copy element text content or input values to the clipboard.

Installation

$ npm install --save clipboard-copy-element

Usage

import 'clipboard-copy-element'
<clipboard-copy for="blob-path" class="btn btn-sm BtnGroup-item">
  Copy path
</clipboard-copy>
<div id="blob-path">src/index.js</div>

Data sources

Attribute

<clipboard-copy value="src/index.js">Copy</clipboard-copy>

Element content

<clipboard-copy for="blob-path">Copy</clipboard-copy>
<div id="blob-path">src/index.js</div>

Form input

<clipboard-copy for="blob-path">Copy</clipboard-copy>
<input id="blob-path" value="src/index.js">

Hyperlink href

<clipboard-copy for="blob-path">Copy full URL</clipboard-copy>
<a id="blob-path" href="/path/to#my-blob">Link text will not be copied</a>

Events

After copying to the clipboard, a clipboard-copy event is dispatched from the <clipboard-copy> element:

document.addEventListener('clipboard-copy', function(event) {
  const button = event.target
  button.classList.add('highlight')
})

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.