From bed29b6ab447b5561c057fcea47f96b97fe34592 Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Thu, 26 Nov 2020 15:58:26 +0100 Subject: [PATCH] Improve display of source blocks --- js/script.js | 13 ++++++++++--- scss/partials/_codes.scss | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/js/script.js b/js/script.js index 3d95b3d..f98f671 100644 --- a/js/script.js +++ b/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); }); } diff --git a/scss/partials/_codes.scss b/scss/partials/_codes.scss index b6d9bbd..13da373 100644 --- a/scss/partials/_codes.scss +++ b/scss/partials/_codes.scss @@ -17,12 +17,28 @@ overflow: visible; margin-top: 1em; + // Caption + label { + text-align: center; + cursor: text; + + .listing-number { + font-weight: bold; + color: #343131; + } + } + // Copy Button div.src-copy { @include src-box; line-height:1.5; right: 10px; cursor: pointer; + + // When button is clicked + &.src-copied { + background-color: #d6e9ff; + } } // Code Block @@ -54,6 +70,7 @@ &.src-python:before { content: 'Python'; } &.src-latex:before { content: 'LaTeX'; } &.src-matlab:before { content: 'Matlab'; } + &.src-bibtex:before { content: 'BibTeX'; } } }