0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-13 21:41:16 +01:00
gitea/web_src/js/features/clipboard.js

23 lines
754 B
JavaScript
Raw Normal View History

export default async function initClipboard() {
const els = document.querySelectorAll('.clipboard');
if (!els || !els.length) return;
const {default: ClipboardJS} = await import(/* webpackChunkName: "clipboard" */'clipboard');
const clipboard = new ClipboardJS(els);
clipboard.on('success', (e) => {
e.clearSelection();
$(e.trigger).popup('destroy');
e.trigger.dataset.content = e.trigger.dataset.success;
$(e.trigger).popup('show');
e.trigger.dataset.content = e.trigger.dataset.original;
});
clipboard.on('error', (e) => {
$(e.trigger).popup('destroy');
e.trigger.dataset.content = e.trigger.dataset.error;
$(e.trigger).popup('show');
e.trigger.dataset.content = e.trigger.dataset.original;
});
}