mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-20 03:29:35 +05:30
(feat): implemented code snippet copy feature and disabled page scrolling when share window is open
This commit is contained in:
@@ -126,7 +126,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<p class="text-xs my-3 text-accent_three">EMBED THIS PAGE</p>
|
<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">
|
<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"><iframe src="https://neosubhamoy.dev" height="200" width="300" title="test iframe"></iframe></code></pre>
|
<pre class="text-accent_four text-xs whitespace-pre-wrap"><code id="embedcodetag"><iframe src="https://neosubhamoy.dev" height="200" width="300" title="test iframe"></iframe></code></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ function activate_share() {
|
|||||||
shareBtn.classList.add("hidden");
|
shareBtn.classList.add("hidden");
|
||||||
shareCloseBtn.classList.remove("hidden");
|
shareCloseBtn.classList.remove("hidden");
|
||||||
shareWin.classList.add("floatingshare-window-show");
|
shareWin.classList.add("floatingshare-window-show");
|
||||||
|
document.body.classList.add("overflow-hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to close the share window
|
// function to close the share window
|
||||||
@@ -331,6 +331,7 @@ function close_share() {
|
|||||||
shareCloseBtn.classList.add("hidden");
|
shareCloseBtn.classList.add("hidden");
|
||||||
shareBtn.classList.remove("hidden");
|
shareBtn.classList.remove("hidden");
|
||||||
shareWin.classList.remove("floatingshare-window-show");
|
shareWin.classList.remove("floatingshare-window-show");
|
||||||
|
document.body.classList.remove("overflow-hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
shareBtn.addEventListener("click", function () {
|
shareBtn.addEventListener("click", function () {
|
||||||
@@ -364,6 +365,9 @@ function call_webshare_api() {
|
|||||||
|
|
||||||
// function to copy text based content to device clipboard
|
// function to copy text based content to device clipboard
|
||||||
function copy_to_clipboard(textContent, copyContext) {
|
function copy_to_clipboard(textContent, copyContext) {
|
||||||
|
if(copyContext === 'Code Snippet') {
|
||||||
|
textContent = textContent.replace(/</g, '<').replace(/>/g, '>');
|
||||||
|
}
|
||||||
if(navigator.clipboard) {
|
if(navigator.clipboard) {
|
||||||
navigator.clipboard.writeText(textContent).then(function() {
|
navigator.clipboard.writeText(textContent).then(function() {
|
||||||
window.alert(copyContext + " Copied to Clipboard");
|
window.alert(copyContext + " Copied to Clipboard");
|
||||||
|
|||||||
Reference in New Issue
Block a user