2022-06-15 14:51:47 +07: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-22 04:57:51 +07:00
|
|
|
/*
|
|
|
|
console.info('Action:', e.action);
|
|
|
|
console.info('Text:', e.text);
|
|
|
|
console.info('Trigger:', e.trigger);
|
|
|
|
*/
|
2022-06-15 14:51:47 +07:00
|
|
|
|
2022-06-22 04:57:51 +07:00
|
|
|
e.clearSelection();
|
2022-06-15 14:51:47 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
clipboard.on('error', function(e) {
|
2022-06-22 04:57:51 +07:00
|
|
|
console.error('Action:', e.action);
|
|
|
|
console.error('Trigger:', e.trigger);
|
2022-06-15 14:51:47 +07:00
|
|
|
});
|