|
1 | | -(function () { |
| 1 | +'use strict'; |
| 2 | + |
| 3 | +(() => { |
2 | 4 | function copyTextToClipboard(text) { |
3 | | - var textArea = document.createElement('textarea'); |
| 5 | + const textArea = document.createElement('textarea'); |
4 | 6 | textArea.value = text; |
5 | 7 | textArea.style.position = 'fixed'; |
6 | 8 | textArea.style.left = '-1'; |
|
11 | 13 | document.execCommand('copy'); |
12 | 14 | document.body.removeChild(textArea); |
13 | 15 | } |
14 | | - var codeBlockElements = document.getElementsByClassName('copyable'); |
15 | | - for (var i = 0; i < codeBlockElements.length; i++) { |
16 | | - var block = codeBlockElements[i]; |
17 | | - var copyIcon = new Image(16, 16); |
| 16 | + const codeBlockElements = document.getElementsByClassName('copyable'); |
| 17 | + for (let i = 0; i < codeBlockElements.length; i++) { |
| 18 | + const block = codeBlockElements[i]; |
| 19 | + const copyIcon = new Image(16, 16); |
18 | 20 | copyIcon.setAttribute('src', './assets/copy-icon.svg'); |
19 | 21 | copyIcon.setAttribute('alt', 'copy'); |
20 | 22 | copyIcon.setAttribute('title', 'copy to clipboard'); |
21 | 23 | block.insertBefore(copyIcon, block.children[0]); |
22 | | - copyIcon.addEventListener('click', function(block) { |
23 | | - var text = block.getElementsByTagName('pre')[0].innerText; |
| 24 | + copyIcon.addEventListener('click', (block) => { |
| 25 | + const text = block.getElementsByTagName('pre')[0].innerText; |
24 | 26 | copyTextToClipboard(text); |
25 | | - }.bind(null, block)); |
| 27 | + }); |
26 | 28 | } |
27 | 29 | })(); |
0 commit comments