Clipboard.js

A modern approach to copy text to clipboard. No Flash. No frameworks. Just 3kb gzipped.

How To

  1. Step 1: Include LambdaEx Framework in Logi Info Application. Include LambdaEx Framework in Logi Info Application.
  2. Step 2: Click here to download Clipboard JS SourceClick here to download Clipboard JS Source

Features

  • No flash file or framework
  • Customazible & extendable
  • Integration with Bootstrap Tooltips
Example
Copy text from input
Cut text from input
Copy with bootstrap tooltip

Options

If you don't want to modify your HTML, there's a pretty handy imperative API for you to use. All you need to do is declare a function, do your thing, and return a value.

ParamDescription
target:For instance, if you want to dynamically set a target, you'll need to return a Node.
text:If you want to dynamically set a text, you'll return a String.
container:For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value.

Methods

ParamDescription
destroyAlso, if you are working with single page apps, you may want to manage the lifecycle of the DOM more precisely. Here's how you clean up the events and objects that we create.
var clipboard = new Clipboard('.btn');
clipboard.destroy();

Events

Show user feedback or capture what has been selected after a copy/cut operation.

EventDescription
successTriggered when the target is successfully copied.
errorTriggered when target cannot be found.
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
   console.info('Action:', e.action);
   console.info('Text:', e.text);
   console.info('Trigger:', e.trigger);

   e.clearSelection();
});

clipboard.on('error', function(e) {
   console.error('Action:', e.action);
   console.error('Trigger:', e.trigger);
});