[docs] add copy to clipboard button for <pre> blocks (#10700)

* [docs] add copy to clickboard button for <pre> blocks

* avoid "let" for now
This commit is contained in:
Ivan Blinkov 2020-05-06 16:30:43 +03:00 committed by GitHub
parent 71027e007d
commit f2371ff7d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,3 @@
<svg width="18" height="21" viewBox="0 0 18 21" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.80019 0.600098C4.91619 0.600098 4.2002 1.3161 4.2002 2.2001V15.0001C4.2002 15.8841 4.91619 16.6001 5.80019 16.6001H16.2002C17.0842 16.6001 17.8002 15.8841 17.8002 15.0001V5.8001C17.8002 5.5881 17.7162 5.38487 17.5658 5.23447L13.1658 0.834473C13.0154 0.684073 12.8122 0.600098 12.6002 0.600098H5.80019ZM12.2002 2.12354L16.2768 6.2001H13.0002C12.5586 6.2001 12.2002 5.8417 12.2002 5.4001V2.12354ZM1.8002 4.6001C0.916195 4.6001 0.200195 5.3161 0.200195 6.2001V19.0001C0.200195 19.8841 0.916195 20.6001 1.8002 20.6001H12.2002C13.0842 20.6001 13.8002 19.8841 13.8002 19.0001V18.2001H5.80019C4.03539 18.2001 2.6002 16.7649 2.6002 15.0001V4.6001H1.8002Z" fill="#C9C9C9"/>
</svg>

After

Width:  |  Height:  |  Size: 780 B

View File

@ -54,6 +54,26 @@
}
});
function copy_to_clipboard(element) {
var temp = $('<textarea></textarea>');
$('body').append(temp);
temp.val($(element).text());
temp.select();
document.execCommand('copy');
temp.remove();
}
$('pre').each(function(_, element) {
$(element).prepend('<img src="/images/mkdocs/copy.svg" class="code-copy btn float-right m-0 p-0" />');
});
$('.code-copy').each(function(_, element) {
element = $(element);
element.click(function() {
copy_to_clipboard(element.parent());
})
});
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
var is_single_page = $('html').attr('data-single-page') === 'true';