Improve display of source blocks

This commit is contained in:
2020-11-26 15:58:26 +01:00
parent 602309beae
commit bed29b6ab4
2 changed files with 27 additions and 3 deletions

View File

@@ -26,16 +26,23 @@ docReady(function() {
// Copy Source Block
docReady(function() {
let srcContainers = document.querySelectorAll('div.org-src-container')
let srcContainers = document.querySelectorAll('pre.src')
for (let srcContrainer of srcContainers) {
let boxCopy = document.createElement('div')
boxCopy.className = "src-copy"
boxCopy.textContent = "Copy"
boxCopy.onclick = function() {
navigator.clipboard.writeText(this.nextElementSibling.textContent).then(function() {
// Get text inside (remove 4 first char corresponding to "Copy")
let srcText = this.parentNode.textContent.slice(4)
navigator.clipboard.writeText(srcText).then(function() {
boxCopy.textContent = "Copied"
setTimeout(function() { boxCopy.textContent = "Copy" },1000);
boxCopy.classList.add("src-copied")
setTimeout(function() {
boxCopy.textContent = "Copy"
boxCopy.classList.remove("src-copied")
},1000);
});
}