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].

florian 2019-06-13 07:49 trunk
Commit ba3e6fe7385867459ffc3344511ac1581c3e01f292c535794eb793d943ca1d89
1 file changed +15 -10
+15 -10
--- src/copybtn.js
+++ src/copybtn.js
@@ -79,16 +79,21 @@
7979
lockCopyText = false;
8080
}.bind(null,this.id),400);
8181
}
8282
/* Create a temporary <textarea> element and copy the contents to clipboard. */
8383
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
+ }
9499
}
95100
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button