2022-06-15 07:51:47 +00:00
|
|
|
import Clipboard from 'clipboard';
|
|
|
|
|
|
|
|
var pre = document.getElementsByTagName('pre');
|
|
|
|
|
|
|
|
for (var i = 0; i < pre.length; ++ i)
|
|
|
|
{
|
|
|
|
var element = pre[i];
|
|
|
|
var mermaid = element.getElementsByClassName('language-mermaid')[0];
|
|
|
|
|
|
|
|
if (mermaid == null) {
|
|
|
|
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) {
|
2022-06-21 21:57:51 +00:00
|
|
|
/*
|
|
|
|
console.info('Action:', e.action);
|
|
|
|
console.info('Text:', e.text);
|
|
|
|
console.info('Trigger:', e.trigger);
|
|
|
|
*/
|
2022-06-15 07:51:47 +00:00
|
|
|
|
2022-06-21 21:57:51 +00:00
|
|
|
e.clearSelection();
|
2022-06-15 07:51:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
clipboard.on('error', function(e) {
|
2022-06-21 21:57:51 +00:00
|
|
|
console.error('Action:', e.action);
|
|
|
|
console.error('Trigger:', e.trigger);
|
2022-06-15 07:51:47 +00:00
|
|
|
});
|