Skip to content

Commit

Permalink
Copy button shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecole committed Jul 9, 2024
1 parent e894b14 commit 717d750
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h1 class="display-4 fst-italic">{{ site.title }}</h1>
for (var i = 0; i < numberOfSnippets; i++) {
var snippet = snippets[i];

//snippets[i].classList.add('hljs'); // append copy button to pre tag
snippet.classList.add('hljs'); // append copy button to pre tag

var language = snippet.getElementsByTagName('code')[0].classList.values().find(f => f.startsWith('language-'));
if (language) {
Expand All @@ -110,7 +110,7 @@ <h1 class="display-4 fst-italic">{{ site.title }}</h1>

snippet.innerHTML = '<button type="button" class="btn btn-primary btn-sm mt-1 mr-1 hljs-copy">Copy</button>' + snippet.innerHTML; // append copy button

parent.getElementsByClassName('hljs-copy')[0].addEventListener("click", function () {
snippet.getElementsByClassName('hljs-copy')[0].addEventListener("click", function () {
this.innerText = 'Copying...';
var code = this.parentNode.getElementsByTagName('code')[0].innerText;
navigator.clipboard.writeText(code);
Expand Down

0 comments on commit 717d750

Please sign in to comment.