Skip to content

Commit a280a30

Browse files
Merge pull request #447 from Listwon/clipboard
Fix copy to clipboard is available only for rust snippets
2 parents cb6f228 + 8960013 commit a280a30

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/theme/book.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ $( document ).ready(function() {
201201
}
202202
});
203203
});
204+
205+
$("pre code").each(function(i, block){
206+
var pre_block = $(this).parent();
207+
if( !pre_block.hasClass('playpen') ) {
208+
var buttons = pre_block.find(".buttons");
209+
if(buttons.length == 0) {
210+
pre_block.prepend("<div class=\"buttons\"></div>");
211+
buttons = pre_block.find(".buttons");
212+
}
213+
buttons.prepend("<i class=\"fa fa-copy clip-button\"><i class=\"tooltiptext\"></i></i>");
214+
buttons.find(".clip-button").mouseout(function(e){
215+
hideTooltip(e.currentTarget);
216+
});
217+
}
218+
});
204219

205220
// Process playpen code blocks
206221
$(".playpen").each(function(block){
@@ -236,7 +251,7 @@ $( document ).ready(function() {
236251
var clipboardSnippets = new Clipboard('.clip-button', {
237252
text: function(trigger) {
238253
hideTooltip(trigger);
239-
let playpen = $(trigger).parents(".playpen");
254+
let playpen = $(trigger).parents("pre");
240255
return playpen_text(playpen);
241256
}
242257
});

0 commit comments

Comments
 (0)