Skip to content

Commit

Permalink
Fix #1276: Add copy to clipboard for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantpandey9 committed Nov 26, 2023
1 parent c14949c commit 4f6b446
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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;
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
14 changes: 14 additions & 0 deletions djangoproject/static/js/mod/clippify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ 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 wrapper = header.parent();
var code = $('.highlight', wrapper);

// Check if the icon has already been added
if (!$('.btn-clipboard', code).length) {
var btn = $('<span class="btn-clipboard" title="Copy this code">');
btn.append('<i class="icon icon-clipboard">');
btn.data('clipboard-text', $.trim(code.text()));
code.append(btn);
}
});

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

0 comments on commit 4f6b446

Please sign in to comment.