Skip to content

Commit 4f6b446

Browse files
Fix #1276: Add copy to clipboard for commands
1 parent c14949c commit 4f6b446

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-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

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ 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 wrapper = header.parent();
14+
var code = $('.highlight', wrapper);
15+
16+
// Check if the icon has already been added
17+
if (!$('.btn-clipboard', code).length) {
18+
var btn = $('<span class="btn-clipboard" title="Copy this code">');
19+
btn.append('<i class="icon icon-clipboard">');
20+
btn.data('clipboard-text', $.trim(code.text()));
21+
code.append(btn);
22+
}
23+
});
24+
1125
// For Django 2.0 docs and older.
1226
$('.snippet').each(function() {
1327
var code = $('.highlight', this);

0 commit comments

Comments
 (0)