Skip to content

Commit 9f23e60

Browse files
committed
fix: copy button visibility issue
1 parent 916b764 commit 9f23e60

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

_sass/components/code.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@
5151
top: 5px;
5252

5353
button {
54-
border: none;
54+
// border: none;
5555
background: #fff;
5656
font-size: $font-size-medium;
5757
color: $gray-darker;
5858
cursor: pointer;
59+
border: 1px solid #E5EAEA;
60+
border-radius: 3px;
61+
margin: 4px;
62+
padding: 3px 5px;
5963
}
6064
}
6165

resources/js/functions.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,3 +705,33 @@ $(document).ready(function() {
705705
}
706706
});
707707
});
708+
709+
710+
711+
$(document).ready(function () {
712+
$("pre > code").each(function () {
713+
const $code = $(this);
714+
// Skip if it's already wrapped in a .code-snippet-area
715+
if ($code.closest(".code-snippet-area").length) return;
716+
717+
const $pre = $code.parent();
718+
const $wrapper = $('<div class="code-snippet-area"></div>');
719+
const $buttons = $(`
720+
<div class="code-snippet-buttons">
721+
<button class="copy-button">
722+
<i class="far fa-clone"></i>
723+
</button>
724+
</div>
725+
`);
726+
727+
$pre.wrap($wrapper);
728+
$pre.before($buttons);
729+
});
730+
731+
$(document).on("click", ".copy-button", function () {
732+
const $button = $(this);
733+
const $area = $button.closest(".code-snippet-area");
734+
const codeText = $area.find("code").text().trim();
735+
navigator.clipboard.writeText(codeText)
736+
});
737+
});

0 commit comments

Comments
 (0)