Skip to content

Commit 204e6ff

Browse files
committed
clean up
1 parent 4489e03 commit 204e6ff

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

web_src/js/features/copycontent.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import {registerGlobalEventFunc} from '../modules/observer.ts';
77
const {i18n} = window.config;
88

99
export function initCopyContent() {
10-
registerGlobalEventFunc('click', 'onCopyContentButtonClick', async (el: HTMLInputElement) => {
11-
if (el.classList.contains('is-loading')) return;
10+
registerGlobalEventFunc('click', 'onCopyContentButtonClick', async (btn: HTMLInputElement) => {
11+
if (btn.classList.contains('disabled') || btn.classList.contains('is-loading')) return;
1212
let content;
1313
let isRasterImage = false;
14-
const link = el.getAttribute('data-link');
14+
const link = btn.getAttribute('data-link');
1515

1616
// when data-link is present, we perform a fetch. this is either because
17-
// the text to copy is not in the DOM or it is an image which should be
17+
// the text to copy is not in the DOM, or it is an image which should be
1818
// fetched to copy in full resolution
1919
if (link) {
20-
el.classList.add('is-loading', 'loading-icon-2px');
20+
btn.classList.add('is-loading', 'loading-icon-2px');
2121
try {
2222
const res = await GET(link, {credentials: 'include', redirect: 'follow'});
2323
const contentType = res.headers.get('content-type');
@@ -29,25 +29,25 @@ export function initCopyContent() {
2929
content = await res.text();
3030
}
3131
} catch {
32-
return showTemporaryTooltip(el, i18n.copy_error);
32+
return showTemporaryTooltip(btn, i18n.copy_error);
3333
} finally {
34-
el.classList.remove('is-loading', 'loading-icon-2px');
34+
btn.classList.remove('is-loading', 'loading-icon-2px');
3535
}
3636
} else { // text, read from DOM
3737
const lineEls = document.querySelectorAll('.file-view .lines-code');
3838
content = Array.from(lineEls, (el) => el.textContent).join('');
3939
}
4040

41-
// try copy original first, if that fails and it's an image, convert it to png
41+
// try copy original first, if that fails, and it's an image, convert it to png
4242
const success = await clippie(content);
4343
if (success) {
44-
showTemporaryTooltip(el, i18n.copy_success);
44+
showTemporaryTooltip(btn, i18n.copy_success);
4545
} else {
4646
if (isRasterImage) {
4747
const success = await clippie(await convertImage(content as Blob, 'image/png'));
48-
showTemporaryTooltip(el, success ? i18n.copy_success : i18n.copy_error);
48+
showTemporaryTooltip(btn, success ? i18n.copy_success : i18n.copy_error);
4949
} else {
50-
showTemporaryTooltip(el, i18n.copy_error);
50+
showTemporaryTooltip(btn, i18n.copy_error);
5151
}
5252
}
5353
});

0 commit comments

Comments
 (0)