mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Adds advanced usage docs
This commit is contained in:
parent
194bf6aeb3
commit
2aff9ab55a
24
README.md
24
README.md
@ -101,6 +101,30 @@ Truth is, you don't even need another element to copy its content from. You can
|
||||
</button>
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
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.
|
||||
|
||||
For instance, if you want to dynamically set a `target`, you'll need to return a Node.
|
||||
|
||||
```js
|
||||
new Clipboard('.btn', {
|
||||
target: function(trigger) {
|
||||
return trigger.nextElementSibling;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
If you want to dynamically set a `text`, you'll return a String.
|
||||
|
||||
```js
|
||||
new Clipboard('.btn', {
|
||||
text: function(trigger) {
|
||||
return trigger.getAttribute('aria-label');
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Events
|
||||
|
||||
There are cases where you'd like to show some user feedback or capture what has been selected after a copy/cut operation.
|
||||
|
Loading…
Reference in New Issue
Block a user