2.1.0 • Published 4 years ago

opusonline-nativecopy.js v2.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

NativeCopy.js

Javascript plugin to copy some text to the clipboard.

This plugin supports:

  • callback for text generation
  • beforeCopy/onSuccess/onError callbacks
  • destroy() method
  • new in v2.1.0 Async Clipboard API

Install

Install with yarn: yarn add opusonline-nativecopy.js

<script src="nativeCopy.js"></script>

Usage

Example

var nativecopy = new NativeCopy('#copyButton', { // copyButton is id of button element, could be any selector for example '.cpBtn'
    text: function() { // or just text: 'This is great!',
        return 'This is great!';
    },
    beforeCopy: function (text) {
        console.log(text);
        // you can do return false; to prevent continuing
    },
    onSuccess: function (text) {
        console.log('success', text);
        this.clearSelection();
    },
    onError: function (text) {
        console.log('error', text);
        alert('Press Ctrl-C to copy');
    }
});

// later
nativecopy.destroy();