diff options
Diffstat (limited to 'layouts/partials/sidebar.html')
-rw-r--r-- | layouts/partials/sidebar.html | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index d4c24ed..48c7e7b 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -13,7 +13,6 @@ <i title="Copy URL to share" class="nav-menu fas fa-share-alt" - onclick="copyUrl({{ .Permalink }})" ></i> </p> <p class="about text-left mb-0"> @@ -26,3 +25,45 @@ </a> </p> </div> + +<script> + function displayCopyMessage(bool) { + let alertMessage = ""; + if (bool) { + alertMessage = "Link copied to clipboard"; + } else { + alertMessage = "Link could not be copied to clipboard"; + } + let copiedMessage = document.createElement("div"); + copiedMessage.id = "copiedMessage"; + copiedMessage.textContent = alertMessage; + copiedMessage.classList.add( + "bg-warning", + "shadow", + "d-block", + "text-center" + ); + document.body.appendChild(copiedMessage); + + setTimeout(function() { + copiedMessage.style.opacity = 0; + }, 500); + setTimeout(function() { + document.body.removeChild(copiedMessage); + }, 1500); + } + + let clipboard = new ClipboardJS(".fa-share-alt", { + text: function() { + return "{{ .Permalink }}"; + } + }); + + clipboard.on("success", function() { + displayCopyMessage(true); + }); + + clipboard.on("error", function() { + displayCopyMessage(false); + }); +</script> |