Skip to content

Commit

Permalink
Fix attachment clipboard copy on insecure origin (#26224) (#26231)
Browse files Browse the repository at this point in the history
Backport #26224.
  • Loading branch information
silverwind authored Jul 30, 2023
1 parent 2122743 commit 0d04f70
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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 {showTemporaryTooltip} from '../modules/tippy.js';

const {appUrl, csrfToken} = window.config;
const {appUrl, csrfToken, i18n} = window.config;

export function initGlobalFormDirtyLeaveConfirm() {
// Warn users that try to leave a page after entering data into a form.
Expand Down Expand Up @@ -146,15 +148,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 0d04f70

Please sign in to comment.