Skip to content

Commit

Permalink
Fix #1276: Add copy to clipboard for commands
Browse files Browse the repository at this point in the history
Fix: code copying logic
  • Loading branch information
prashantpandey9 committed Dec 7, 2023
1 parent c14949c commit 04ba5fe
Show file tree
Hide file tree
Showing 3 changed files with 24 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
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

0 comments on commit 04ba5fe

Please sign in to comment.