Sha256: 2f143245f831cf35dd8bf0a331d1dd6b8d2a20c3ccf4df2b072f89ecc5a1cc05
Contents?: true
Size: 1.74 KB
Versions: 22
Compression:
Stored size: 1.74 KB
Contents
function testCopyComand() { try { document.execCommand("copy") return true } catch (error) { return false } } function addClickToCopyButton(codeBlocks) { codeBlocks.map(function(codeBlock, index){ var clickToCopyButton = createButton() codeBlock.appendChild(clickToCopyButton) clickToCopyButton.addEventListener('click', function(e) { selectElementRange(this.parentNode) }) }) } function selectElementRange(copyElementSelect) { var range = document.createRange() range.selectNode(copyElementSelect) window.getSelection().removeAllRanges() window.getSelection().addRange(range) document.execCommand("copy") window.getSelection().removeAllRanges() } function createButton() { var copyButton = document.createElement('button') copyButton.className = 'ae-btn ae-btn-primary click-to-copy' copyButton.data = 'Click to copy' var clipboard = document.createElement('i') clipboard.className = 'fa fa-clipboard' copyButton.appendChild(clipboard) return copyButton } function addClickToCopyText() { var codeBlockButtons = Array.prototype.slice.call(document.querySelectorAll('.ae-code-block .ae-btn')) codeBlockButtons.map(function(button, index) { var pre = button.closest('pre') button.setAttribute('data-tooltip', 'Click to copy') button.addEventListener('click', function(e){ button.setAttribute('data-tooltip', 'Copied!') setTimeout(function(){ button.setAttribute('data-tooltip', 'Click to copy')}, 500) }) }) } document.addEventListener("DOMContentLoaded", function() { if (testCopyComand()) { var codeBlocks = Array.prototype.slice.call(document.querySelectorAll(".ae-code-block")) addClickToCopyButton(codeBlocks) addClickToCopyText() } })
Version data entries
22 entries across 22 versions & 1 rubygems