2020-02-07 23:03:42 +00:00
|
|
|
export default async function initClipboard() {
|
|
|
|
const els = document.querySelectorAll('.clipboard');
|
|
|
|
if (!els || !els.length) return;
|
|
|
|
|
2020-03-11 19:34:54 +00:00
|
|
|
const {default: ClipboardJS} = await import(/* webpackChunkName: "clipboard" */'clipboard');
|
2020-02-07 23:03:42 +00:00
|
|
|
|
|
|
|
const clipboard = new ClipboardJS(els);
|
|
|
|
clipboard.on('success', (e) => {
|
|
|
|
e.clearSelection();
|
2020-06-09 21:31:15 +00:00
|
|
|
$(e.trigger).popup('destroy');
|
|
|
|
e.trigger.dataset.content = e.trigger.dataset.success;
|
|
|
|
$(e.trigger).popup('show');
|
|
|
|
e.trigger.dataset.content = e.trigger.dataset.original;
|
2020-02-07 23:03:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
clipboard.on('error', (e) => {
|
2020-06-09 21:31:15 +00:00
|
|
|
$(e.trigger).popup('destroy');
|
|
|
|
e.trigger.dataset.content = e.trigger.dataset.error;
|
|
|
|
$(e.trigger).popup('show');
|
|
|
|
e.trigger.dataset.content = e.trigger.dataset.original;
|
2020-02-07 23:03:42 +00:00
|
|
|
});
|
|
|
|
}
|