2020-02-07 16:03:42 -07:00
|
|
|
export default async function initClipboard() {
|
|
|
|
const els = document.querySelectorAll('.clipboard');
|
|
|
|
if (!els || !els.length) return;
|
|
|
|
|
2020-03-11 13:34:54 -06:00
|
|
|
const {default: ClipboardJS} = await import(/* webpackChunkName: "clipboard" */'clipboard');
|
2020-02-07 16:03:42 -07:00
|
|
|
|
|
|
|
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'));
|
|
|
|
});
|
|
|
|
}
|