diff --git a/assets/scripts/clipboard.js b/assets/scripts/clipboard.js index e929fcf..42c2c84 100644 --- a/assets/scripts/clipboard.js +++ b/assets/scripts/clipboard.js @@ -5,10 +5,14 @@ clipboard.on('success', function(e) { console.info('Action:', e.action); console.info('Text:', e.text); + console.info('Trigger:', e.trigger); showTooltip(e.trigger, 'Copied!'); }); clipboard.on('error', function(e) { + console.error('Action:', e.action); + console.error('Trigger:', e.trigger); + showTooltip(e.trigger, fallbackMessage(e.action)); }); diff --git a/index.html b/index.html index daadc67..9898fe8 100644 --- a/index.html +++ b/index.html @@ -32,8 +32,6 @@ allowtransparency="true" frameborder="0" scrolling="0" width="156" height="30"><
That's why clipboard.js exists.
-And don't be a jerk, use it responsibly :)
-You can get it on npm.
@@ -52,33 +50,24 @@ allowtransparency="true" frameborder="0" scrolling="0" width="156" height="30"><<script src="dist/clipboard.min.js"></script>
- Now, you need to instantiate it using a DOM selector. This selector corresponds to the trigger element, i.e. <button>
.
Now, you need to instantiate it using a DOM selector. This selector corresponds to the trigger element(s), for example <button class="btn">
.
new Clipboard('.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.
+ +For this reason we use event delegation which replaces multiple event listeners with just a single listener. After all, #perfmatters.
+We're living a declarative renaissance, that's why we decided to take advantage of HTML5 data attributes for better usability.
-The easiest way to copy some content to the clipboard, is to include a data-text
attribute in your trigger element.
<!-- Trigger -->
-<button class="btn" data-text="Just because you can doesn't mean you should — clipboard.js">
- Copy to clipboard
-</button>
-
Alternatively, you can copy content from another element by adding a data-target
attribute in your trigger element.
A pretty common use case is to copy content from another element. You can do that by adding a data-target
attribute in your trigger element.
The value you include on this attribute needs to match another's element id
attribute.