Skip to content

Commit b24fb6c

Browse files
committed
Fix attachment clipboard copy on insecure origin (go-gitea#26224)
1 parent 2122743 commit b24fb6c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

web_src/js/features/common-global.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import $ from 'jquery';
22
import 'jquery.are-you-sure';
3+
import {clippie} from 'clippie';
34
import {createDropzone} from './dropzone.js';
45
import {initCompColorPicker} from './comp/ColorPicker.js';
56
import {showGlobalErrorMessage} from '../bootstrap.js';
67
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js';
78
import {svg} from '../svg.js';
89
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
910
import {htmlEscape} from 'escape-goat';
11+
import {showTemporaryTooltip} from '../modules/tippy.js';
1012

11-
const {appUrl, csrfToken} = window.config;
13+
const {appUrl, csrfToken, i18n} = window.config;
1214

1315
export function initGlobalFormDirtyLeaveConfirm() {
1416
// Warn users that try to leave a page after entering data into a form.
@@ -146,15 +148,16 @@ export function initGlobalDropzone() {
146148
copyLinkElement.className = 'gt-text-center';
147149
// The a element has a hardcoded cursor: pointer because the default is overridden by .dropzone
148150
copyLinkElement.innerHTML = `<a href="#" style="cursor: pointer;">${svg('octicon-copy', 14, 'copy link')} Copy link</a>`;
149-
copyLinkElement.addEventListener('click', (e) => {
151+
copyLinkElement.addEventListener('click', async (e) => {
150152
e.preventDefault();
151153
let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`;
152154
if (file.type.startsWith('image/')) {
153155
fileMarkdown = `!${fileMarkdown}`;
154156
} else if (file.type.startsWith('video/')) {
155157
fileMarkdown = `<video src="/attachments/${file.uuid}" title="${htmlEscape(file.name)}" controls></video>`;
156158
}
157-
navigator.clipboard.writeText(fileMarkdown);
159+
const success = await clippie(fileMarkdown);
160+
showTemporaryTooltip(e.target, success ? i18n.copy_success : i18n.copy_error);
158161
});
159162
file.previewTemplate.append(copyLinkElement);
160163
});

0 commit comments

Comments
 (0)