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

Fix #1276: Add copy to clipboard icon for commands #1434

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
13 changes: 13 additions & 0 deletions djangoproject/scss/_console-tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@
>.c-tab-win:checked~.c-content-win {
display: block;
}
>.c-content-win, >.c-content-unix .highlight-console{
.highlight{
display: flex;
justify-content: space-between;

.btn-clipboard{
float: right;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you have to use float here? You are using flexbox, I think it's better to keep everything in flex then

position: sticky;
cursor: pointer;
margin: 15px;
}
}
}
}
2 changes: 1 addition & 1 deletion djangoproject/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ define(function() {
mods.push('mod/messages');
}

if (hasClass('code-block-caption') || hasClass('snippet')) {
if (hasClass('code-block-caption') || hasClass('snippet') || hasClass('c-content-unix') || hasClass('c-content-win')){
mods.push('mod/clippify');
}

Expand Down
10 changes: 10 additions & 0 deletions djangoproject/static/js/mod/clippify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ define(['jquery', 'clipboard'], function($, Clipboard) {
btn.data('clipboard-text', $.trim(code.text()));
header.append(btn);
});
$('.c-content-win, .c-content-unix').each(function() {
var header = $(this);
var code = $('.highlight', header);
// Check if the icon has already been added
var btn = $('<span class="btn-clipboard" title="Copy this code">');
btn.append('<i class="icon icon-clipboard">');
btn.data('clipboard-text', $.trim(code.clone().find('.gp, .go').remove().end().text()));
code.append(btn);
});

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