Skip to content

Commit

Permalink
Merge pull request #2 from MeForma/true-first
Browse files Browse the repository at this point in the history
Reorder the code to execute as a true-first strategy
  • Loading branch information
jprodrigues70 committed Oct 10, 2023
2 parents b6d4454 + 9dce3a0 commit dd0fd28
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
export default {
install: (app) => {
app.config.globalProperties.$copyText = (text) => {
if (!navigator.clipboard) {
const textArea = document.createElement('textarea')
textArea.value = text
if (navigator.clipboard) {
return navigator.clipboard.writeText(text)
}

textArea.style.top = '0'
textArea.style.left = '0'
textArea.style.position = 'fixed'
const textArea = document.createElement('textarea')
textArea.value = text

document.body.appendChild(textArea)
textArea.focus()
textArea.select()
textArea.style.top = '0'
textArea.style.left = '0'
textArea.style.position = 'fixed'

try {
document.execCommand('copy')
document.body.removeChild(textArea)
return Promise.resolve()
} catch (err) {
document.body.removeChild(textArea)
return Promise.reject(err)
}
}
document.body.appendChild(textArea)
textArea.focus()
textArea.select()

return navigator.clipboard.writeText(text)
try {
document.execCommand('copy')
document.body.removeChild(textArea)
return Promise.resolve()
} catch (err) {
document.body.removeChild(textArea)
return Promise.reject(err)
}
}
}
}

0 comments on commit dd0fd28

Please sign in to comment.