added workaround to copy arbitrary text to che clipboard

This commit is contained in:
Roberto Tonino
2020-08-19 17:35:25 +02:00
parent 40c7ba9a0c
commit e1a3e8b562
3 changed files with 37 additions and 16 deletions

View File

@@ -73,6 +73,24 @@ export function debounce(func, wait, immediate) {
}
}
/**
* Workaround to copy to the clipboard cross-OS by generating a
* ghost input and copying the passed String
*
* @param {string} text Text to copy
*/
export function copyToClipboard(text) {
const ghostInput = document.createElement('input')
document.body.appendChild(ghostInput)
ghostInput.setAttribute('type', 'text')
ghostInput.setAttribute('value', text)
ghostInput.select()
ghostInput.setSelectionRange(0, 99999)
document.execCommand('copy')
ghostInput.remove()
}
export const COUNTRIES = {
AF: 'Afghanistan',
AX: '\u00c5land Islands',