Skip to content

Commit

Permalink
Function copy icon restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Jan 24, 2025
1 parent 3fd38a2 commit 04b574f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion web/resources/function.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="function-type-title" style="color: {{type_colors[function.type_name]}};">{{ function.type_name|capitalize }} function</div>
<h1 style="border-bottom: 3px solid {{type_colors[function.type_name]}}; padding-bottom: 0.2em;">
<span {% if function.disabled %}style="text-decoration: line-through;"{% endif %}>{{ function.name }}</span>
<a class="small-fs" href="#" onclick="copyText('{{ function.name }}', 'copy-{{ function.name }}')"><i class="fa-regular fa-copy"></i> <span id="copy-{{ function.name }}">Copy</span> </a>
<a class="small-fs" href="#" onclick="copyText('{{ function.name }}', 'copy-{{ function.name }}')"><i class="fa-regular fa-copy"></i> <span id="copy-{{ function.name }}"></span> </a>
</h1>

<!-- Disabled Warning -->
Expand Down
14 changes: 10 additions & 4 deletions web/resources/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
});
});

var copyTextTimer = null;
var copyTexts = {};
async function copyText(text, spanCopyText) {
event.preventDefault()
const type = "text/plain";
Expand All @@ -124,10 +124,16 @@
await navigator.clipboard.write(data);
if (spanCopyText) {
spanCopyText = document.getElementById(spanCopyText);
if (copyTexts[spanCopyText]) {
clearTimeout(copyTexts[spanCopyText]["timer"]);
} else {
copyTexts[spanCopyText] = {};
}
copyTexts[spanCopyText]["oldText"] = spanCopyText.innerText;
spanCopyText.innerText = "Copied!";
clearTimeout(copyTextTimer);
copyTextTimer = setTimeout(() => {
spanCopyText.innerText = "Copy";
copyTexts[spanCopyText]["timer"] = setTimeout(() => {
spanCopyText.innerText = copyTexts[spanCopyText]["oldText"];
delete copyTexts[spanCopyText];
}, 2000);
}
}
Expand Down

0 comments on commit 04b574f

Please sign in to comment.