0
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-30 10:05:10 +01:00
gitea/web_src/js/features/clipboard.js
silverwind e03d627769
Misc JS linting and naming tweaks (#10652)
- lowercase all js filenames except Vue components
- enable new lint rules, mostly focused on shorter code
- autofix new lint violations
- apply misc transformations indexOf -> includes and onevent-> addEventListener

Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
2020-03-11 21:34:54 +02:00

24 lines
955 B
JavaScript

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.getAttribute('id')}`).popup('destroy');
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-success'));
$(`#${e.trigger.getAttribute('id')}`).popup('show');
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
});
clipboard.on('error', (e) => {
$(`#${e.trigger.getAttribute('id')}`).popup('destroy');
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-error'));
$(`#${e.trigger.getAttribute('id')}`).popup('show');
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
});
}