You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
955 B

  1. export default async function initClipboard() {
  2. const els = document.querySelectorAll('.clipboard');
  3. if (!els || !els.length) return;
  4. const {default: ClipboardJS} = await import(/* webpackChunkName: "clipboard" */'clipboard');
  5. const clipboard = new ClipboardJS(els);
  6. clipboard.on('success', (e) => {
  7. e.clearSelection();
  8. $(`#${e.trigger.getAttribute('id')}`).popup('destroy');
  9. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-success'));
  10. $(`#${e.trigger.getAttribute('id')}`).popup('show');
  11. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
  12. });
  13. clipboard.on('error', (e) => {
  14. $(`#${e.trigger.getAttribute('id')}`).popup('destroy');
  15. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-error'));
  16. $(`#${e.trigger.getAttribute('id')}`).popup('show');
  17. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
  18. });
  19. }