Skip to content

Commit

Permalink
fix #1221
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmueller committed Aug 10, 2023
1 parent d6b40b4 commit c4250e1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project tries to adhere to https://semver.org/spec/v2.0.0.html[Semantic

=== added

* https://github.com/docToolchain/docToolchain/issues/1230[#1230 generateSite: copy to clipboard]

=== changed

== 3.0.0-rc1 - 2023-07-13
Expand Down
2 changes: 2 additions & 0 deletions src/docs/010_manual/20_install.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include::../_feedback.adoc[]

== Installation Overview

icon:copy[] icon:clipboard[] icon:tags[]

docToolchain is composed of two parts:

- `doctoolchain` which is the toolchain used to create your documentation
Expand Down
17 changes: 11 additions & 6 deletions src/site/assets/js/copy-n-paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ document.addEventListener('DOMContentLoaded', function() {

copyDivs.forEach(div => {
// Create a button
const btn = document.createElement('i');
btn.classList.add(['fa-light', 'fa-clipboard'])

const span = document.createElement('span')
span.classList.add('icon')

const icon = document.createElement('i');
icon.classList.add('fa')
icon.classList.add('fa-clipboard')
span.appendChild(icon)

// Add click event to the button
btn.addEventListener('click', async function() {
icon.addEventListener('click', async function() {
try {
await copyTableToClipboard(div);
alert('Code copied to clipboard!');
Expand All @@ -18,12 +23,12 @@ document.addEventListener('DOMContentLoaded', function() {
});

// Append the button to the div
div.appendChild(btn);
div.appendChild(span);
});
});

async function copyTableToClipboard(listingblock) {
const code = listingblock.querySelector('div.content').innerText;
const code = listingblock.querySelector('div.content').innerText+"\n";
const blob = new Blob([code], { type: 'text/plain' });
const data = [new ClipboardItem({ 'text/plain': blob })];
await navigator.clipboard.write(data);
Expand Down
21 changes: 20 additions & 1 deletion src/site/templates/header.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,24 @@
}
</style>


<!-- copy-n-paste.js -->
<style>
div.listingblock {
position: relative;
}
div.listingblock > span.icon {
position: absolute;
top: 2px;
right: 6px;
visibility: hidden;
z-index: 2;
cursor: pointer;
}
div.listingblock:hover > span.icon {
visibility: visible;
}
div.listingblock div.content pre {
margin: 0;
}
</style>
</head>

0 comments on commit c4250e1

Please sign in to comment.