Zero-dependency solution for copying text. Light as a croissant 🥐
$ npm install kopio.js --save
Text from data attribute:
<button class="kopio" data-kopio-text="my text to copy">copy</button>
Specify a target:
<button class="kopio" data-kopio-target="#target">copy</button>
<p id="target">Here is some text I want to be able to be copied.</p>
import Kopio from 'kopio.js'
// using default selector '.kopio'
new Kopio()
// or a custom selector
new Kopio('.custom')
Text from data attribute:
<button class="kopio" data-kopio-text="my text to copy">copy</button>
Specify a target:
<button class="kopio" data-kopio-target="#target">copy</button>
<p id="target">Here is some text I want to be able to be copied.</p>
Saving the object enables subscribing to the copy events. There are only two events success and error. Both events pass the event triggerer as a parameter for the callback.
const kopio = new Kopio()
kopio.on('success', (trigger) => {
})
kopio.on('error', (trigger) => {
})
Released under the MIT license by Andreas Siivola.