|
1 | 1 | import $ from 'jquery'; |
2 | 2 | import 'jquery.are-you-sure'; |
| 3 | +import {clippie} from 'clippie'; |
3 | 4 | import {createDropzone} from './dropzone.js'; |
4 | 5 | import {initCompColorPicker} from './comp/ColorPicker.js'; |
5 | 6 | import {showGlobalErrorMessage} from '../bootstrap.js'; |
6 | 7 | import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js'; |
7 | 8 | import {svg} from '../svg.js'; |
8 | 9 | import {hideElem, showElem, toggleElem} from '../utils/dom.js'; |
9 | 10 | import {htmlEscape} from 'escape-goat'; |
| 11 | +import {showTemporaryTooltip} from '../modules/tippy.js'; |
10 | 12 |
|
11 | | -const {appUrl, csrfToken} = window.config; |
| 13 | +const {appUrl, csrfToken, i18n} = window.config; |
12 | 14 |
|
13 | 15 | export function initGlobalFormDirtyLeaveConfirm() { |
14 | 16 | // Warn users that try to leave a page after entering data into a form. |
@@ -146,15 +148,16 @@ export function initGlobalDropzone() { |
146 | 148 | copyLinkElement.className = 'gt-text-center'; |
147 | 149 | // The a element has a hardcoded cursor: pointer because the default is overridden by .dropzone |
148 | 150 | 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) => { |
150 | 152 | e.preventDefault(); |
151 | 153 | let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`; |
152 | 154 | if (file.type.startsWith('image/')) { |
153 | 155 | fileMarkdown = `!${fileMarkdown}`; |
154 | 156 | } else if (file.type.startsWith('video/')) { |
155 | 157 | fileMarkdown = `<video src="/attachments/${file.uuid}" title="${htmlEscape(file.name)}" controls></video>`; |
156 | 158 | } |
157 | | - navigator.clipboard.writeText(fileMarkdown); |
| 159 | + const success = await clippie(fileMarkdown); |
| 160 | + showTemporaryTooltip(e.target, success ? i18n.copy_success : i18n.copy_error); |
158 | 161 | }); |
159 | 162 | file.previewTemplate.append(copyLinkElement); |
160 | 163 | }); |
|
0 commit comments