2021-03-01 16:34:43 +01:00
|
|
|
import Clipboard from 'clipboard';
|
|
|
|
|
2021-06-17 11:20:48 +02:00
|
|
|
var pre = document.getElementsByTagName('pre');
|
|
|
|
|
|
|
|
for (var i = 0; i < pre.length; ++ i)
|
|
|
|
{
|
|
|
|
var element = pre[i];
|
2021-07-01 16:21:03 +02:00
|
|
|
var mermaid = element.getElementsByClassName('language-mermaid')[0];
|
|
|
|
|
|
|
|
if (mermaid == null) {
|
|
|
|
element.insertAdjacentHTML('afterbegin', '<button class="btn btn-copy"></button>');
|
|
|
|
}
|
2021-06-17 11:20:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var clipboard = new Clipboard('.btn-copy', {
|
|
|
|
|
|
|
|
target: function(trigger) {
|
|
|
|
return trigger.nextElementSibling;
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
2021-03-01 16:34:43 +01:00
|
|
|
|
|
|
|
clipboard.on('success', function(e) {
|
2021-06-17 11:20:48 +02:00
|
|
|
|
2021-03-01 16:34:43 +01:00
|
|
|
/*
|
|
|
|
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);
|
|
|
|
});
|