Fix some incorrect async functions, improve frontend document. (#17597)
This commit is contained in:
parent
0db7a32b92
commit
7f802631c5
7 changed files with 106 additions and 43 deletions
|
@ -46,7 +46,7 @@ function fallbackCopyToClipboard(text) {
|
|||
}
|
||||
|
||||
export default function initGlobalCopyToClipboardListener() {
|
||||
document.addEventListener('click', async (e) => {
|
||||
document.addEventListener('click', (e) => {
|
||||
let target = e.target;
|
||||
// in case <button data-clipboard-text><svg></button>, so we just search up to 3 levels for performance.
|
||||
for (let i = 0; i < 3 && target; i++) {
|
||||
|
@ -58,16 +58,20 @@ export default function initGlobalCopyToClipboardListener() {
|
|||
}
|
||||
if (text) {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
onSuccess(target);
|
||||
} catch {
|
||||
if (fallbackCopyToClipboard(text)) {
|
||||
|
||||
(async() => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
onSuccess(target);
|
||||
} else {
|
||||
onError(target);
|
||||
} catch {
|
||||
if (fallbackCopyToClipboard(text)) {
|
||||
onSuccess(target);
|
||||
} else {
|
||||
onError(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
break;
|
||||
}
|
||||
target = target.parentElement;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue