Fallback to copy to clipboard without HTTPS
This commit is contained in:
parent
ca97a4d745
commit
725feb8d01
1 changed files with 33 additions and 2 deletions
|
@ -1332,6 +1332,34 @@ L.U.Map.include({
|
|||
formData.append('name', this.options.name)
|
||||
formData.append('center', JSON.stringify(this.geometry()))
|
||||
formData.append('settings', JSON.stringify(geojson))
|
||||
|
||||
function copyToClipboard(textToCopy) {
|
||||
// https://stackoverflow.com/a/65996386
|
||||
// Navigator clipboard api needs a secure context (https)
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(textToCopy)
|
||||
} else {
|
||||
// Use the 'out of viewport hidden text area' trick
|
||||
const textArea = document.createElement('textarea')
|
||||
textArea.value = textToCopy
|
||||
|
||||
// Move textarea out of the viewport so it's not visible
|
||||
textArea.style.position = 'absolute'
|
||||
textArea.style.left = '-999999px'
|
||||
|
||||
document.body.prepend(textArea)
|
||||
textArea.select()
|
||||
|
||||
try {
|
||||
document.execCommand('copy')
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
textArea.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.post(this.getSaveUrl(), {
|
||||
data: formData,
|
||||
context: this,
|
||||
|
@ -1363,8 +1391,11 @@ L.U.Map.include({
|
|||
{
|
||||
label: L._('Copy link'),
|
||||
callback: () => {
|
||||
navigator.clipboard.writeText(data.permissions.anonymous_edit_url)
|
||||
this.ui.alert({content: L._('Copied!'), level: 'info'})
|
||||
copyToClipboard(data.permissions.anonymous_edit_url)
|
||||
this.ui.alert({
|
||||
content: L._('Secret edit link copied to clipboard!'),
|
||||
level: 'info',
|
||||
})
|
||||
},
|
||||
callbackContext: this,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue