Fossil SCM
Update the copyTextToClipboard() Javascript function to suppress scrolling, and remove the temporary textarea in case of an error (i.e. blocked clipboard access), as suggested here: [https://fossil-scm.org/forum/forumpost/40189d7d2f].
Commit
ba3e6fe7385867459ffc3344511ac1581c3e01f292c535794eb793d943ca1d89
Parent
34fcaf829a908db…
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 |