Skip to content

Commit

Permalink
Fixed copy button on code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bamr87 committed May 16, 2024
1 parent b84cbbc commit 1ed1f15
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
1 change: 1 addition & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script src="/assets/js/back-to-top.js"></script>
<script src="/assets/js/halfmoon.js"></script>
<script src="/assets/js/side-bar-folders.js"></script>
<script src="/assets/js/code-copy.js"></script>


<!-- third party scripts -->
Expand Down
37 changes: 13 additions & 24 deletions _sass/it-journey/code-copy.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// https://remarkablemark.org/blog/2021/06/01/add-copy-code-to-clipboard-button-to-jeyll-site/

.gist {
td {
border: inherit; // fix Skeleton override
}
}

//Codeblock


.copy-code {
display: inline-block;
margin: 0 0.5em;
padding: 0.5em 1em;
color: white;
background-color: black;
border: none;
cursor: pointer;
}

pre.highlight {
padding: 8px 12px;
Expand Down Expand Up @@ -88,25 +91,11 @@ pre>code {
white-space: pre;
}

.btn-clipboard {
position: relative;
z-index: 2;
margin-top: .75rem;
margin-right: .75rem
}

.bd-clipboard,.bd-edit {
position: relative;
pre.has-copy-button .copy {
display: none;
float: right
}

.bd-clipboard+.highlight,.bd-edit+.highlight {
margin-top: 0
}

@media (min-width: 768px) {
.bd-clipboard,.bd-edit {
display:block
}
pre.has-copy-button:hover .copy {
display: inline-block;
}
1 change: 0 additions & 1 deletion assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@

// Custom Features
@import "it-journey/code-copy";
@import "it-journey/clipboard-js";
@import "it-journey/syntax";

9 changes: 5 additions & 4 deletions assets/js/code-copy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copy code to clipboard

document
document.addEventListener('DOMContentLoaded', function () {
document
.querySelectorAll('pre.highlight')
.forEach(function (pre) {
var button = document.createElement('button');
Expand All @@ -18,4 +17,6 @@ document
}, 4000);
});
pre.appendChild(button);
});
pre.classList.add('has-copy-button'); // Add a class to the pre element
});
});

0 comments on commit 1ed1f15

Please sign in to comment.