Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1276 -- Added copy buttons to console and shell commands. #1447

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions djangoproject/scss/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3624,6 +3624,11 @@ ul.corporate-members li {
}

.code-block-caption,
.highlight-console,
.c-content-win,
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's missing .c-content-unix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need as there is a child div with .highlight-console for every section with .c-content-unix.
2024-06-10_13-52

.highlight-shell,
.highlight-doscon,
.literal-block,
.snippet {
.btn-clipboard {
float: right;
Expand Down
8 changes: 7 additions & 1 deletion djangoproject/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ define(function() {
mods.push('mod/messages');
}

if (hasClass('code-block-caption') || hasClass('snippet')) {
if (hasClass('code-block-caption') ||
hasClass('snippet') ||
hasClass('highlight-console') ||
hasClass('c-content-win') ||
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, I think it's missing .c-content-unix

hasClass('highlight-shell') ||
hasClass('highlight-doscon') ||
hasClass('literal-block')) {
mods.push('mod/clippify');
}

Expand Down
26 changes: 20 additions & 6 deletions djangoproject/static/js/mod/clippify.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
define(['jquery', 'clipboard'], function($, Clipboard) {
$('.code-block-caption').each(function() {
var header = $(this);
var wrapper = header.parent();
var code = $('.highlight', wrapper);
function addCopyButton(btnParent, code){
var btn = $('<span class="btn-clipboard" title="Copy this code">');
btn.append('<i class="icon icon-clipboard">');
btn.data('clipboard-text', $.trim(code.text()));
header.append(btn);
btn.data('clipboard-text', $.trim(code));
btnParent.prepend(btn);
};
$('.code-block-caption').each(function(){
var header = $(this);
var wrapper = header.parent();
var codeBlock = $('pre', wrapper);
addCopyButton(header, codeBlock.text())
});
$('.highlight-console, .c-content-win, .highlight-shell, .highlight-doscon').each(function(){
var codeBlock = $('pre', this);
var clone = $(codeBlock).clone();
$('.gp, .go', clone).remove();
addCopyButton(codeBlock, clone.text());
});
$('#download .literal-block').each(function () {
var codeBlock = $(this);
addCopyButton(codeBlock, codeBlock.text());
});

// For Django 2.0 docs and older.
$('.snippet').each(function() {
var code = $('.highlight', this);
Expand Down