11 |
12 |
13 |
14 |
46 |
47 |
73 |
--------------------------------------------------------------------------------
/utils/clipboard.js:
--------------------------------------------------------------------------------
1 | // From: https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
2 | export function copyTextToClipboard(text) {
3 | const textArea = document.createElement('textarea')
4 |
5 | //
6 | // *** This styling is an extra step which is likely not required. ***
7 | //
8 | // Why is it here? To ensure:
9 | // 1. the element is able to have focus and selection.
10 | // 2. if element was to flash render it has minimal visual impact.
11 | // 3. less flakyness with selection and copying which **might** occur if
12 | // the textarea element is not visible.
13 | //
14 | // The likelihood is the element won't even render, not even a flash,
15 | // so some of these are just precautions. However in IE the element
16 | // is visible whilst the popup box asking the user for permission for
17 | // the web page to copy to the clipboard.
18 | //
19 |
20 | // Place in top-left corner of screen regardless of scroll position.
21 | textArea.style.position = 'fixed'
22 | textArea.style.top = 0
23 | textArea.style.left = 0
24 |
25 | // Ensure it has a small width and height. Setting to 1px / 1em
26 | // doesn't work as this gives a negative w/h on some browsers.
27 | textArea.style.width = '2em'
28 | textArea.style.height = '2em'
29 |
30 | // We don't need padding, reducing the size if it does flash render.
31 | textArea.style.padding = 0
32 |
33 | // Clean up any borders.
34 | textArea.style.border = 'none'
35 | textArea.style.outline = 'none'
36 | textArea.style.boxShadow = 'none'
37 |
38 | // Avoid flash of white box if rendered for any reason.
39 | textArea.style.background = 'transparent'
40 |
41 | textArea.value = text
42 |
43 | document.body.appendChild(textArea)
44 |
45 | textArea.select()
46 |
47 | try {
48 | document.execCommand('copy')
49 | } catch (err) {
50 | console.error('Unable to copy text')
51 | }
52 |
53 | document.body.removeChild(textArea)
54 | }
55 |
--------------------------------------------------------------------------------
/layouts/default.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |