forked from cybrespace/pinafore
		
	fix: fix "copy link" on iOS (#918)
* fix: fix "copy link" on iOS fixes #912 * fix lint
This commit is contained in:
		
							parent
							
								
									2656e11bb0
								
							
						
					
					
						commit
						0b1efab0c1
					
				
					 1 changed files with 12 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -32,6 +32,17 @@
 | 
			
		|||
  import { toast } from '../../toast/toast'
 | 
			
		||||
  import { doubleRAF } from '../../../_utils/doubleRAF'
 | 
			
		||||
 | 
			
		||||
  function copyFromInput (input) {
 | 
			
		||||
    // workarounds for iOS, via https://stackoverflow.com/a/34046084
 | 
			
		||||
    let range = document.createRange()
 | 
			
		||||
    range.selectNodeContents(input)
 | 
			
		||||
    let selection = window.getSelection()
 | 
			
		||||
    selection.removeAllRanges()
 | 
			
		||||
    selection.addRange(range)
 | 
			
		||||
    input.setSelectionRange(0, 9999999)
 | 
			
		||||
    document.execCommand('copy')
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  export default {
 | 
			
		||||
    oncreate () {
 | 
			
		||||
      onCreateDialog.call(this)
 | 
			
		||||
| 
						 | 
				
			
			@ -48,8 +59,7 @@
 | 
			
		|||
      close,
 | 
			
		||||
      onClick () {
 | 
			
		||||
        let { input } = this.refs
 | 
			
		||||
        input.select()
 | 
			
		||||
        document.execCommand('copy')
 | 
			
		||||
        copyFromInput(input)
 | 
			
		||||
        toast.say('Copied to clipboard')
 | 
			
		||||
        this.close()
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue