Skip to content

Commit 04ba5fe

Browse files
Fix #1276: Add copy to clipboard for commands
Fix: code copying logic
1 parent c14949c commit 04ba5fe

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

djangoproject/scss/_console-tabs.scss

+13
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,17 @@
4444
>.c-tab-win:checked~.c-content-win {
4545
display: block;
4646
}
47+
>.c-content-win, >.c-content-unix .highlight-console{
48+
.highlight{
49+
display: flex;
50+
justify-content: space-between;
51+
52+
.btn-clipboard{
53+
float: right;
54+
position: sticky;
55+
cursor: pointer;
56+
margin: 15px;
57+
}
58+
}
59+
}
4760
}

djangoproject/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ define(function() {
9898
mods.push('mod/messages');
9999
}
100100

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

djangoproject/static/js/mod/clippify.js

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ define(['jquery', 'clipboard'], function($, Clipboard) {
88
btn.data('clipboard-text', $.trim(code.text()));
99
header.append(btn);
1010
});
11+
$('.c-content-win, .c-content-unix').each(function() {
12+
var header = $(this);
13+
var code = $('.highlight', header);
14+
// Check if the icon has already been added
15+
var btn = $('<span class="btn-clipboard" title="Copy this code">');
16+
btn.append('<i class="icon icon-clipboard">');
17+
btn.data('clipboard-text', $.trim(code.clone().find('.gp, .go').remove().end().text()));
18+
code.append(btn);
19+
});
20+
1121
// For Django 2.0 docs and older.
1222
$('.snippet').each(function() {
1323
var code = $('.highlight', this);

0 commit comments

Comments
 (0)