You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
645 B
18 lines
645 B
function initCopyButtons() { |
|
$('.copy').remove(); |
|
$('div.highlight').each(function () { |
|
var $btn = $('<button>', { class: 'copy', type: 'button', text: '📋' }); |
|
$(this).append($btn); |
|
$btn.on('click', function () { |
|
var code = $btn.siblings('pre').find('code').text().trim(); |
|
navigator.clipboard.writeText(code) |
|
.then(function () { $btn.text('✅'); }) |
|
.catch(function () { $btn.text('❌'); }) |
|
.finally(function () { setTimeout(function () { $btn.text('📋'); }, 1500); }); |
|
}); |
|
}); |
|
} |
|
|
|
$(function () { |
|
initCopyButtons(); |
|
}); |