Improve display of source blocks
This commit is contained in:
13
js/script.js
13
js/script.js
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user