docs: avoid showing "Copied" if copying fails (#3397)
I noticed that in denoland/fresh#3393 it looks like it's possible that the "Copied"/Check icon will be shown even if copying to clipboard fails. This PR changes it so that the Check icon only shows if copy succeeds.
This commit is contained in:
+1
-10
@@ -94,16 +94,7 @@ html[data-theme="dark"] ::selection {
|
|||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group:not([data-copied]) .group-not-copied {
|
.group[data-copied] .group-not-copied,
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.group[data-copied] .group-not-copied {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.group[data-copied] .group-copied {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.group:not([data-copied]) .group-copied {
|
.group:not([data-copied]) .group-copied {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -11,14 +11,14 @@ document.addEventListener("click", async (ev) => {
|
|||||||
const code = el.dataset.code;
|
const code = el.dataset.code;
|
||||||
if (!code) return;
|
if (!code) return;
|
||||||
|
|
||||||
el.dataset.copied = "true";
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
delete el.dataset.copied;
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(code);
|
await navigator.clipboard.writeText(code);
|
||||||
|
|
||||||
|
el.dataset.copied = "true";
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
delete el.dataset.copied;
|
||||||
|
}, 1000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
// deno-lint-ignore no-console
|
// deno-lint-ignore no-console
|
||||||
|
|||||||
Reference in New Issue
Block a user