Skip to content

Commit

Permalink
Fix attachment clipboard copy on insecure origin (go-gitea#26224)
Browse files Browse the repository at this point in the history
Fixes: go-gitea#26202

Actually later I found out the code did not use `clippie`, so I fixed
it. The bug was never in the clippie module like I initially suspected.
Also, I added a tooltip for feedback.

<img width="139" alt="image"
src="https://github.com/go-gitea/gitea/assets/115237/da501670-9c15-4412-969a-b559773c7ab9">

---------

Co-authored-by: Giteabot <teabot@gitea.io>
  • Loading branch information
silverwind and GiteaBot authored Jul 29, 2023
1 parent 1107425 commit 72d89eb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import $ from 'jquery';
import 'jquery.are-you-sure';
import {clippie} from 'clippie';
import {createDropzone} from './dropzone.js';
import {initCompColorPicker} from './comp/ColorPicker.js';
import {showGlobalErrorMessage} from '../bootstrap.js';
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js';
import {svg} from '../svg.js';
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
import {htmlEscape} from 'escape-goat';
import {createTippy} from '../modules/tippy.js';
import {createTippy, showTemporaryTooltip} from '../modules/tippy.js';
import {confirmModal} from './comp/ConfirmModal.js';
import {showErrorToast} from '../modules/toast.js';

Expand Down Expand Up @@ -240,15 +241,16 @@ export function initGlobalDropzone() {
copyLinkElement.className = 'gt-text-center';
// The a element has a hardcoded cursor: pointer because the default is overridden by .dropzone
copyLinkElement.innerHTML = `<a href="#" style="cursor: pointer;">${svg('octicon-copy', 14, 'copy link')} Copy link</a>`;
copyLinkElement.addEventListener('click', (e) => {
copyLinkElement.addEventListener('click', async (e) => {
e.preventDefault();
let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`;
if (file.type.startsWith('image/')) {
fileMarkdown = `!${fileMarkdown}`;
} else if (file.type.startsWith('video/')) {
fileMarkdown = `<video src="/attachments/${file.uuid}" title="${htmlEscape(file.name)}" controls></video>`;
}
navigator.clipboard.writeText(fileMarkdown);
const success = await clippie(fileMarkdown);
showTemporaryTooltip(e.target, success ? i18n.copy_success : i18n.copy_error);
});
file.previewTemplate.append(copyLinkElement);
});
Expand Down

0 comments on commit 72d89eb

Please sign in to comment.