mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
5 months ago
|
import {showTemporaryTooltip} from '../modules/tippy.ts';
|
||
|
import {toAbsoluteUrl} from '../utils.ts';
|
||
2 years ago
|
import {clippie} from 'clippie';
|
||
3 years ago
|
|
||
3 years ago
|
const {copy_success, copy_error} = window.config.i18n;
|
||
5 years ago
|
|
||
1 year ago
|
// Enable clipboard copy from HTML attributes. These properties are supported:
|
||
9 months ago
|
// - data-clipboard-text: Direct text to copy
|
||
1 year ago
|
// - data-clipboard-target: Holds a selector for a <input> or <textarea> whose content is copied
|
||
|
// - data-clipboard-text-type: When set to 'url' will convert relative to absolute urls
|
||
2 years ago
|
export function initGlobalCopyToClipboardListener() {
|
||
9 months ago
|
document.addEventListener('click', async (e) => {
|
||
|
const target = e.target.closest('[data-clipboard-text], [data-clipboard-target]');
|
||
|
if (!target) return;
|
||
1 year ago
|
|
||
9 months ago
|
e.preventDefault();
|
||
1 year ago
|
|
||
8 months ago
|
let text = target.getAttribute('data-clipboard-text');
|
||
|
if (!text) {
|
||
9 months ago
|
text = document.querySelector(target.getAttribute('data-clipboard-target'))?.value;
|
||
|
}
|
||
3 years ago
|
|
||
9 months ago
|
if (text && target.getAttribute('data-clipboard-text-type') === 'url') {
|
||
|
text = toAbsoluteUrl(text);
|
||
|
}
|
||
1 year ago
|
|
||
9 months ago
|
if (text) {
|
||
|
const success = await clippie(text);
|
||
|
showTemporaryTooltip(target, success ? copy_success : copy_error);
|
||
3 years ago
|
}
|
||
|
});
|
||
5 years ago
|
}
|