From 016b8726c8bba7070de5fb6be6b7773193837059 Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Wed, 8 Nov 2023 20:28:42 -0600 Subject: [PATCH] remove unused code --- assets/js/code-copy-button.js | 40 ++++++++++++++--------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/assets/js/code-copy-button.js b/assets/js/code-copy-button.js index 26f1d0b..aff9abc 100644 --- a/assets/js/code-copy-button.js +++ b/assets/js/code-copy-button.js @@ -33,32 +33,24 @@ async function copyCodeToClipboard(button, highlightDiv) { if (result.state == "granted" || result.state == "prompt") { await navigator.clipboard.writeText(codeToCopy); } else { - copyCodeBlockExecCommand(codeToCopy, highlightDiv); + button.blur(); + button.innerText = "Error!"; + setTimeout(function () { + button.innerText = "Copy"; + }, 2000); } } catch (_) { - copyCodeBlockExecCommand(codeToCopy, highlightDiv); + button.blur(); + button.innerText = "Error!"; + setTimeout(function () { + button.innerText = "Copy"; + }, 2000); } finally { - button.blur(); - button.innerText = "Copied!"; - setTimeout(function () { - button.innerText = "Copy"; - }, 2000); } + button.blur(); + button.innerText = "Copied!"; + setTimeout(function () { + button.innerText = "Copy"; + }, 2000); + } } -function copyCodeBlockExecCommand(codeToCopy, highlightDiv) { - console.log("We shouldn't get here..."); - const textArea = document.createElement("textArea"); - textArea.contentEditable = "true"; - textArea.readOnly = "false"; - textArea.className = "copyable-text-area"; - textArea.value = codeToCopy; - highlightDiv.insertBefore(textArea, highlightDiv.firstChild); - const range = document.createRange(); - range.selectNodeContents(textArea); - const sel = window.getSelection(); - sel.removeAllRanges(); - sel.addRange(range); - textArea.setSelectionRange(0, 999999); - document.execCommand("copy"); - highlightDiv.removeChild(textArea); -}