From e1d571b3f33612322e4d77bbb4ed58d7ce09c9a3 Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Wed, 28 Feb 2018 22:07:10 -0800 Subject: [PATCH] Updates docs to use ClipboardJS 2.0 --- readme.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index af69f37..76692ff 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ First, include the script located on the `dist` folder or load it from [a third- Now, you need to instantiate it by [passing a DOM selector](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-selector.html#L18), [HTML element](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-node.html#L16-L17), or [list of HTML elements](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-nodelist.html#L18-L19). ```js -new Clipboard('.btn'); +new ClipboardJS('.btn'); ``` Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guess what? If you have hundreds of matches, this operation can consume a lot of memory. @@ -103,7 +103,7 @@ There are cases where you'd like to show some user feedback or capture what has That's why we fire custom events such as `success` and `error` for you to listen and implement your custom logic. ```js -var clipboard = new Clipboard('.btn'); +var clipboard = new ClipboardJS('.btn'); clipboard.on('success', function(e) { console.info('Action:', e.action); @@ -134,7 +134,7 @@ If you don't want to modify your HTML, there's a pretty handy imperative API for For instance, if you want to dynamically set a `target`, you'll need to return a Node. ```js -new Clipboard('.btn', { +new ClipboardJS('.btn', { target: function(trigger) { return trigger.nextElementSibling; } @@ -144,7 +144,7 @@ new Clipboard('.btn', { If you want to dynamically set a `text`, you'll return a String. ```js -new Clipboard('.btn', { +new ClipboardJS('.btn', { text: function(trigger) { return trigger.getAttribute('aria-label'); } @@ -154,7 +154,7 @@ new Clipboard('.btn', { 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. ```js -new Clipboard('.btn', { +new ClipboardJS('.btn', { container: document.getElementById('modal') }); ``` @@ -162,7 +162,7 @@ new Clipboard('.btn', { Also, 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. ```js -var clipboard = new Clipboard('.btn'); +var clipboard = new ClipboardJS('.btn'); clipboard.destroy(); ``` @@ -176,7 +176,7 @@ This library relies on both [Selection](https://developer.mozilla.org/en-US/docs The good news is that clipboard.js gracefully degrades if you need to support older browsers. All you have to do is show a tooltip saying `Copied!` when `success` event is called and `Press Ctrl+C to copy` when `error` event is called because the text is already selected. -You can also check if clipboard.js is supported or not by running `Clipboard.isSupported()`, that way you can hide copy/cut buttons from the UI. +You can also check if clipboard.js is supported or not by running `ClipboardJS.isSupported()`, that way you can hide copy/cut buttons from the UI. ## Bonus