mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Add copy to clipboard fallback
This commit is contained in:
		
							parent
							
								
									d22e9e32ed
								
							
						
					
					
						commit
						4d227cbade
					
				| @ -163,17 +163,26 @@ Vue.prototype.$sanitizeSlug = (str) => { | |||||||
| Vue.prototype.$copyToClipboard = (str, ctx) => { | Vue.prototype.$copyToClipboard = (str, ctx) => { | ||||||
|   return new Promise((resolve) => { |   return new Promise((resolve) => { | ||||||
|     if (!navigator.clipboard) { |     if (!navigator.clipboard) { | ||||||
|       console.warn('Clipboard not supported') |       navigator.clipboard.writeText(str).then(() => { | ||||||
|       return resolve(false) |         if (ctx) ctx.$toast.success('Copied to clipboard') | ||||||
|  |         resolve(true) | ||||||
|  |       }, (err) => { | ||||||
|  |         console.error('Clipboard copy failed', str, err) | ||||||
|  |         resolve(false) | ||||||
|  |       }) | ||||||
|  |     } else { | ||||||
|  |       const el = document.createElement('textarea') | ||||||
|  |       el.value = str | ||||||
|  |       el.setAttribute('readonly', '') | ||||||
|  |       el.style.position = 'absolute' | ||||||
|  |       el.style.left = '-9999px' | ||||||
|  |       document.body.appendChild(el) | ||||||
|  |       el.select() | ||||||
|  |       document.execCommand('copy') | ||||||
|  |       document.body.removeChild(el) | ||||||
|  | 
 | ||||||
|  |       if (ctx) ctx.$toast.success('Copied to clipboard') | ||||||
|     } |     } | ||||||
|     navigator.clipboard.writeText(str).then(() => { |  | ||||||
|       console.log('Clipboard copy success', str) |  | ||||||
|       ctx.$toast.success('Copied to clipboard') |  | ||||||
|       resolve(true) |  | ||||||
|     }, (err) => { |  | ||||||
|       console.error('Clipboard copy failed', str, err) |  | ||||||
|       resolve(false) |  | ||||||
|     }) |  | ||||||
|   }) |   }) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user