Updates site to use ClipboardJS 2.0

This commit is contained in:
Zeno Rocha
2018-02-28 21:59:23 -08:00
parent c07957f59f
commit 2874e9e2e0
5 changed files with 951 additions and 12 deletions

View File

@@ -53,7 +53,7 @@ allowtransparency="true" frameborder="0" scrolling="0" width="156" height="30"><
<p>Now, you need to instantiate it by <a href="https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-selector.html#L18">passing a DOM selector</a>, <a href="https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-node.html#L16-L17">HTML element</a>, or <a href="https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-nodelist.html#L18-L19">list of HTML elements</a>.</p>
<pre class="snippet"><code class="js">new Clipboard('.btn');</code></pre>
<pre class="snippet"><code class="js">new ClipboardJS('.btn');</code></pre>
<p>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.</p>
@@ -132,7 +132,7 @@ allowtransparency="true" frameborder="0" scrolling="0" width="156" height="30"><
<p>That's why we fire custom events such as <code>success</code> and <code>error</code> for you to listen and implement your custom logic.</p>
<pre class="snippet"><code class="js">var clipboard = new Clipboard('.btn');
<pre class="snippet"><code class="js">var clipboard = new ClipboardJS('.btn');
clipboard.on('success', function(e) {
console.info('Action:', e.action);
@@ -161,7 +161,7 @@ clipboard.on('error', function(e) {
<p>For instance, if you want to dynamically set a <code>target</code>, you'll need to return a Node.</p>
<pre class="snippet"><code class="js">new Clipboard('.btn', {
<pre class="snippet"><code class="js">new ClipboardJS('.btn', {
target: function(trigger) {
return trigger.nextElementSibling;
}
@@ -169,7 +169,7 @@ clipboard.on('error', function(e) {
<p>If you want to dynamically set a <code>text</code>, you'll return a String.</p>
<pre class="snippet"><code class="js">new Clipboard('.btn', {
<pre class="snippet"><code class="js">new ClipboardJS('.btn', {
text: function(trigger) {
return trigger.getAttribute('aria-label');
}
@@ -177,13 +177,13 @@ clipboard.on('error', function(e) {
<p>For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the <code>container</code> value.</p>
<pre class="snippet"><code class="js">new Clipboard('.btn', {
<pre class="snippet"><code class="js">new ClipboardJS('.btn', {
container: document.getElementById('modal')
});</code></pre>
<p>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.</p>
<pre class="snippet"><code class="js">var clipboard = new Clipboard('.btn');
<pre class="snippet"><code class="js">var clipboard = new ClipboardJS('.btn');
clipboard.destroy();</code></pre>
<h1 id="browser-support">Browser Support</h1>
@@ -219,7 +219,7 @@ clipboard.destroy();</code></pre>
<p>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 <code>Copied!</code> when <code>success</code> event is called and <code>Press Ctrl+C to copy</code> when <code>error</code> event is called because the text is already selected.</p>
<p>You can also check if clipboard.js is supported or not by running <code>Clipboard.isSupported()</code>, that way you can hide copy/cut buttons from the UI.</p>
<p>You can also check if clipboard.js is supported or not by running <code>ClipboardJS.isSupported()</code>, that way you can hide copy/cut buttons from the UI.</p>
<h1 id="bonus">Bonus</h1>