|
| 1 | +;(function () { |
| 2 | + 'use strict' |
| 3 | + |
| 4 | + ;[].slice.call(document.querySelectorAll('.doc pre.highlight, .doc .literalblock pre')).forEach(function (pre) { |
| 5 | + var code, language, lang, copy, toast, toolbox |
| 6 | + if (pre.classList.contains('highlight')) { |
| 7 | + code = pre.querySelector('code') |
| 8 | + if ((language = code.dataset.lang) && language !== 'console') { |
| 9 | + ;(lang = document.createElement('span')).className = 'code-lang' |
| 10 | + lang.appendChild(document.createTextNode(language)) |
| 11 | + } |
| 12 | + } else if (pre.innerText.startsWith('$ ')) { |
| 13 | + var block = pre.parentNode.parentNode |
| 14 | + block.classList.remove('literalblock') |
| 15 | + block.classList.add('listingblock') |
| 16 | + pre.classList.add('highlightjs') |
| 17 | + pre.classList.add('highlight') |
| 18 | + ;(code = document.createElement('code')).className = 'language-console hljs' |
| 19 | + code.dataset.lang = 'console' |
| 20 | + code.appendChild(pre.firstChild) |
| 21 | + pre.appendChild(code) |
| 22 | + } else { |
| 23 | + return |
| 24 | + } |
| 25 | + ;(copy = document.createElement('button')).className = 'copy-button' |
| 26 | + copy.setAttribute('title', 'Copy to clipboard') |
| 27 | + var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg') |
| 28 | + svg.setAttribute('class', 'copy-icon') |
| 29 | + svg.setAttribute('aria-hidden', 'true') |
| 30 | + svg.setAttribute('data-prefix', 'far') |
| 31 | + svg.setAttribute('data-icon', 'copy') |
| 32 | + svg.setAttribute('data-version', '5.10.2') |
| 33 | + svg.setAttribute('role', 'img') |
| 34 | + svg.setAttribute('viewBox', '0 0 448 512') |
| 35 | + var path = document.createElementNS('http://www.w3.org/2000/svg', 'path') |
| 36 | + path.setAttribute('fill', 'currentColor') |
| 37 | + path.setAttribute( |
| 38 | + 'd', |
| 39 | + 'M433.941 65.941l-51.882-51.882A48 48 0 0 0 348.118 0H176c-26.51 0-48 21.49-48 48v48H48c-26.51 0-48 21.49-48 48v320c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48v-48h80c26.51 0 48-21.49 48-48V99.882a48 48 0 0 0-14.059-33.941zM266 464H54a6 6 0 0 1-6-6V150a6 6 0 0 1 6-6h74v224c0 26.51 21.49 48 48 48h96v42a6 6 0 0 1-6 6zm128-96H182a6 6 0 0 1-6-6V54a6 6 0 0 1 6-6h106v88c0 13.255 10.745 24 24 24h88v202a6 6 0 0 1-6 6zm6-256h-64V48h9.632c1.591 0 3.117.632 4.243 1.757l48.368 48.368a6 6 0 0 1 1.757 4.243V112z' // eslint-disable-line max-len |
| 40 | + ) |
| 41 | + svg.appendChild(path) |
| 42 | + copy.appendChild(svg) |
| 43 | + ;(toast = document.createElement('span')).className = 'copy-toast' |
| 44 | + toast.appendChild(document.createTextNode('Copied!')) |
| 45 | + copy.appendChild(toast) |
| 46 | + ;(toolbox = document.createElement('div')).className = 'code-toolbox' |
| 47 | + if (lang) toolbox.appendChild(lang) |
| 48 | + toolbox.appendChild(copy) |
| 49 | + pre.appendChild(toolbox) |
| 50 | + copy.addEventListener('click', writeToClipboard.bind(copy, code)) |
| 51 | + }) |
| 52 | + |
| 53 | + function writeToClipboard (code) { |
| 54 | + var text = code.innerText |
| 55 | + if (code.dataset.lang === 'console' && text.startsWith('$ ')) text = text.split('\n')[0].slice(2) |
| 56 | + window.navigator.clipboard.writeText(text).then( |
| 57 | + function () { |
| 58 | + this.classList.add('clicked') |
| 59 | + this.offsetHeight // eslint-disable-line no-unused-expressions |
| 60 | + this.classList.remove('clicked') |
| 61 | + }.bind(this), |
| 62 | + function () {} |
| 63 | + ) |
| 64 | + } |
| 65 | +})() |
0 commit comments