//=include clipboard/dist/clipboard.js document.addEventListener('DOMContentLoaded', (event) => { // Clipboard button const clipboardImage = '' const successImage = '' const clipboardButton = `` const codeBlocks = document.querySelectorAll('.highlight') codeBlocks.forEach(codeBlock => { const language = codeBlock.getElementsByTagName('code')[0].dataset.lang codeBlock.insertAdjacentHTML('afterbegin', clipboardButton) codeBlock.insertAdjacentHTML('afterbegin', `
${language}
`) }) const buttons = document.querySelectorAll('.highlight .btn--clipboard') buttons.forEach(button => { const clipboard = new ClipboardJS(button, { target: (trigger) => { return trigger.nextElementSibling; } }) clipboard.on('success', e => { e.trigger.classList.add('success') e.trigger.innerHTML = successImage e.trigger.insertAdjacentHTML('afterend', 'Copied to clipboard') e.clearSelection() }) }) })