Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/callmecavs/gotem
Copy to clipboard for modern browsers in less than 1kb.
https://github.com/callmecavs/gotem
clipboard copy
Last synced: about 1 month ago
JSON representation
Copy to clipboard for modern browsers in less than 1kb.
- Host: GitHub
- URL: https://github.com/callmecavs/gotem
- Owner: callmecavs
- Created: 2017-01-28T00:44:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-31T20:02:31.000Z (over 7 years ago)
- Last Synced: 2024-09-21T23:20:10.775Z (3 months ago)
- Topics: clipboard, copy
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 428
- Watchers: 14
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - gotem Copy to clipboard for modern browsers in less than 1kb.
README
# gotem
[![gotem on NPM](https://img.shields.io/npm/v/gotem.svg?style=flat-square)](https://www.npmjs.com/package/gotem) [![Standard JavaScript Style](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
Copy to clipboard for modern browsers in less than 1kb.
## Install
```sh
$ npm i gotem --save
```## Use
`gotem` is a function that accepts 3 parameters:
1. A **required** trigger node.
2. A **required** target node.
3. An **optional** object of callback functions.Examples follow:
```javascript
import gotem from 'gotem'// a trigger and target node are required
const nodes = {
trigger: document.getElementById('trigger'),
target: document.getElementById('target')
}// when the trigger is clicked,
// the text of the target will be copied to the clipboard
gotem(nodes.trigger, nodes.target)// if an object with callback functions (success, error) is passed,
// the appropriate function, based on the result of executing the copy command, will be fired if it exists
gotem(nodes.trigger, nodes.target, {
success: () => console.log('Copy command succeeded'),
error: () => console.log('Copy command failed, BUT the text to copy has still been selected.')
})
```## Browser Support
gotem requires [`execCommand`](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) cut/copy support.
As such, it works in the following:
* Chrome 43+
* Firefox 41+
* Safari 10+
* Edge 12+
* IE 9+## License
[MIT](https://opensource.org/licenses/MIT). © 2017 Michael Cavalea