feat: auto copy button code
This commit is contained in:
@ -1,8 +1,23 @@
|
||||
import Clipboard from 'clipboard';
|
||||
|
||||
var clipboard = new Clipboard('.btn-clipboard');
|
||||
var pre = document.getElementsByTagName('pre');
|
||||
|
||||
for (var i = 0; i < pre.length; ++ i)
|
||||
{
|
||||
var element = pre[i];
|
||||
element.insertAdjacentHTML('afterbegin', '<button class="btn btn-copy"></button>');
|
||||
}
|
||||
|
||||
var clipboard = new Clipboard('.btn-copy', {
|
||||
|
||||
target: function(trigger) {
|
||||
return trigger.nextElementSibling;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
|
||||
/*
|
||||
console.info('Action:', e.action);
|
||||
console.info('Text:', e.text);
|
||||
|
Reference in New Issue
Block a user