1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-19 23:59:35 +05:30

(feat): implemented code snippet copy feature and disabled page scrolling when share window is open

This commit is contained in:
2023-11-28 21:48:06 +05:30
parent 574c84fd4e
commit 1871e73532
2 changed files with 6 additions and 2 deletions

View File

@@ -126,7 +126,7 @@
</div>
<p class="text-xs my-3 text-accent_three">EMBED THIS PAGE</p>
<div class="embedpagecode w-full bg-bg_primary p-4 rounded-lg relative">
<button class="copyembedcode absolute top-3 right-3 px-3 py-2 bg-bg_secondary rounded-lg" title="Copy code snippet"><i class="fa-regular fa-copy"></i></button>
<button class="copyembedcode absolute top-3 right-3 px-3 py-2 bg-bg_secondary rounded-lg hover:bg-bg_third transition transform duration-500" title="Copy code snippet" onclick="copy_to_clipboard(document.getElementById('embedcodetag').innerHTML, 'Code Snippet')"><i class="fa-regular fa-copy"></i></button>
<pre class="text-accent_four text-xs whitespace-pre-wrap"><code id="embedcodetag">&lt;iframe&#13;&#10;src="https://neosubhamoy.dev"&#13;&#10;height="200"&#13;&#10;width="300"&#13;&#10;title="test iframe"&gt;&lt;/iframe&gt;</code></pre>
</div>
</div>

View File

@@ -321,7 +321,7 @@ function activate_share() {
shareBtn.classList.add("hidden");
shareCloseBtn.classList.remove("hidden");
shareWin.classList.add("floatingshare-window-show");
document.body.classList.add("overflow-hidden");
}
// function to close the share window
@@ -331,6 +331,7 @@ function close_share() {
shareCloseBtn.classList.add("hidden");
shareBtn.classList.remove("hidden");
shareWin.classList.remove("floatingshare-window-show");
document.body.classList.remove("overflow-hidden");
}
shareBtn.addEventListener("click", function () {
@@ -364,6 +365,9 @@ function call_webshare_api() {
// function to copy text based content to device clipboard
function copy_to_clipboard(textContent, copyContext) {
if(copyContext === 'Code Snippet') {
textContent = textContent.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}
if(navigator.clipboard) {
navigator.clipboard.writeText(textContent).then(function() {
window.alert(copyContext + " Copied to Clipboard");