Skip to content

Commit d265c22

Browse files
authored
Merge pull request #61 from kube-HPC/fix_copy_button
fixed "Copy" or "Copied!" being copied when copying code
2 parents 9d738ab + 1ae3119 commit d265c22

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

site/_css/copy-button.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
border-radius: 5px;
77
cursor: pointer;
88
font-size: 12px;
9+
position: absolute;
10+
bottom: 10px;
11+
right: 10px;
912
}
1013

1114
.copy-btn:hover {

site/learn/InstallHkubeCLI.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export os="linux" # or macos
3434
<pre class="bash" id="bashCode">
3535
curl -Lo hkubectl hkube-domain.com/hkubectl_files/hkubectl-${os} \
3636
&& chmod +x hkubectl \
37-
&& sudo mv hkubectl /usr/local/bin/
38-
<button id="copyBtn" onclick="copyToClipboard('bashCode')" class="copy-btn">Copy</button>
37+
&& sudo mv hkubectl /usr/local/bin/<button id="copyBtn" onclick="copyToClipboard('bashCode')" class="copy-btn">Copy</button>
3938
</pre>
4039

4140
<p>For <strong>Windows</strong>, download <code>hkubectl-win.exe</code> from <a id="windowsLink" href="/hkubectl_files/hkubectl-win.exe">here</a>.</p>
@@ -80,23 +79,27 @@ kubectl get nodes
8079
<script>
8180
function copyToClipboard(elementId) {
8281
var code = document.getElementById(elementId);
82+
var copyButton = document.getElementById("copyBtn");
83+
84+
copyButton.textContent = "";
85+
8386
var range = document.createRange();
8487
range.selectNode(code);
8588
window.getSelection().removeAllRanges();
8689
window.getSelection().addRange(range);
8790

8891
try {
8992
document.execCommand("copy");
90-
var copyButton = document.getElementById("copyBtn");
91-
copyButton.textContent = "Copied!";
93+
copyButton.textContent = "Copied!";
94+
95+
setTimeout(function() {
96+
copyButton.textContent = "Copy";
97+
}, 300);
9298

93-
setTimeout(function() {
94-
copyButton.textContent = "Copy";
95-
}, 300);
9699
} catch (err) {
100+
copyButton.textContent = "Copy";
97101
console.error("Unable to copy code", err);
98102
}
99-
100103
window.getSelection().removeAllRanges();
101104
}
102105
</script>

0 commit comments

Comments
 (0)