diff options
Diffstat (limited to 'web_src/js/features/clipboard.js')
-rw-r--r-- | web_src/js/features/clipboard.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/web_src/js/features/clipboard.js b/web_src/js/features/clipboard.js new file mode 100644 index 0000000000..bd4a664c7a --- /dev/null +++ b/web_src/js/features/clipboard.js @@ -0,0 +1,23 @@ +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')); + }); +} |