update code style

This commit is contained in:
vitormalencar
2021-01-21 11:45:33 +01:00
parent d8a51544bd
commit 971834388c
16 changed files with 216 additions and 216 deletions

View File

@@ -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 ClipboardJS(".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.
@@ -106,19 +106,19 @@ 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 ClipboardJS(".btn");
var clipboard = new ClipboardJS('.btn');
clipboard.on("success", function (e) {
console.info("Action:", e.action);
console.info("Text:", e.text);
console.info("Trigger:", e.trigger);
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);
clipboard.on('error', function (e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});
```
@@ -137,7 +137,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 ClipboardJS(".btn", {
new ClipboardJS('.btn', {
target: function (trigger) {
return trigger.nextElementSibling;
},
@@ -147,9 +147,9 @@ new ClipboardJS(".btn", {
If you want to dynamically set a `text`, you'll return a String.
```js
new ClipboardJS(".btn", {
new ClipboardJS('.btn', {
text: function (trigger) {
return trigger.getAttribute("aria-label");
return trigger.getAttribute('aria-label');
},
});
```
@@ -157,15 +157,15 @@ new ClipboardJS(".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 ClipboardJS(".btn", {
container: document.getElementById("modal"),
new ClipboardJS('.btn', {
container: document.getElementById('modal'),
});
```
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 ClipboardJS(".btn");
var clipboard = new ClipboardJS('.btn');
clipboard.destroy();
```