summaryrefslogtreecommitdiffstats
path: root/web_src/js/features/clipboard.js
blob: 32eff981b8fc67bb907fa5eea21856b96b720a02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
  });
}