Fossil SCM
Update the copyTextToClipboard() javascript routine to work better cross-platform.
Commit
0904aa8b10fb9fb939f8e1f254edc8ee3d769f946393cc65944d38c4da4beb6e
Parent
a7e86f5b186b481…
1 file changed
+15
-10
+15
-10
| --- src/copybtn.js | ||
| +++ src/copybtn.js | ||
| @@ -79,16 +79,21 @@ | ||
| 79 | 79 | lockCopyText = false; |
| 80 | 80 | }.bind(null,this.id),400); |
| 81 | 81 | } |
| 82 | 82 | /* Create a temporary <textarea> element and copy the contents to clipboard. */ |
| 83 | 83 | function copyTextToClipboard(text){ |
| 84 | - var x = document.createElement("textarea"); | |
| 85 | - x.style.position = 'absolute'; | |
| 86 | - x.style.left = '-9999px'; | |
| 87 | - x.value = text; | |
| 88 | - document.body.appendChild(x); | |
| 89 | - x.select(); | |
| 90 | - try{ | |
| 91 | - document.execCommand('copy'); | |
| 92 | - }catch(err){} | |
| 93 | - document.body.removeChild(x); | |
| 84 | + if( window.clipboardData && window.clipboardData.setData ){ | |
| 85 | + clipboardData.setData('Text',text); | |
| 86 | + }else{ | |
| 87 | + var x = document.createElement("textarea"); | |
| 88 | + x.style.position = 'fixed'; | |
| 89 | + x.value = text; | |
| 90 | + document.body.appendChild(x); | |
| 91 | + x.select(); | |
| 92 | + try{ | |
| 93 | + document.execCommand('copy'); | |
| 94 | + }catch(err){ | |
| 95 | + }finally{ | |
| 96 | + document.body.removeChild(x); | |
| 97 | + } | |
| 98 | + } | |
| 94 | 99 | } |
| 95 | 100 |
| --- src/copybtn.js | |
| +++ src/copybtn.js | |
| @@ -79,16 +79,21 @@ | |
| 79 | lockCopyText = false; |
| 80 | }.bind(null,this.id),400); |
| 81 | } |
| 82 | /* Create a temporary <textarea> element and copy the contents to clipboard. */ |
| 83 | function copyTextToClipboard(text){ |
| 84 | var x = document.createElement("textarea"); |
| 85 | x.style.position = 'absolute'; |
| 86 | x.style.left = '-9999px'; |
| 87 | x.value = text; |
| 88 | document.body.appendChild(x); |
| 89 | x.select(); |
| 90 | try{ |
| 91 | document.execCommand('copy'); |
| 92 | }catch(err){} |
| 93 | document.body.removeChild(x); |
| 94 | } |
| 95 |
| --- src/copybtn.js | |
| +++ src/copybtn.js | |
| @@ -79,16 +79,21 @@ | |
| 79 | lockCopyText = false; |
| 80 | }.bind(null,this.id),400); |
| 81 | } |
| 82 | /* Create a temporary <textarea> element and copy the contents to clipboard. */ |
| 83 | function copyTextToClipboard(text){ |
| 84 | if( window.clipboardData && window.clipboardData.setData ){ |
| 85 | clipboardData.setData('Text',text); |
| 86 | }else{ |
| 87 | var x = document.createElement("textarea"); |
| 88 | x.style.position = 'fixed'; |
| 89 | x.value = text; |
| 90 | document.body.appendChild(x); |
| 91 | x.select(); |
| 92 | try{ |
| 93 | document.execCommand('copy'); |
| 94 | }catch(err){ |
| 95 | }finally{ |
| 96 | document.body.removeChild(x); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 |