Fossil SCM

Cherry-pick [6a54cf2939]: Trim leading and trailing white space from the text to be copied to clipboard (do this in Javascript, so no need to care about the extra white space when generating HTML elements).

florian 2019-06-02 12:35 copybtn.js-demonstration
Commit 698245db8d9f2837d41e1067fa23fa55e24744427024bbc6f126db2b1a1c5e0b
1 file changed +1 -1
+1 -1
--- src/copybtn.js
+++ src/copybtn.js
@@ -58,11 +58,11 @@
5858
this.style.transition = "opacity 400ms ease-in-out";
5959
this.style.opacity = 0;
6060
var idTarget = this.getAttribute("data-copytarget");
6161
var elTarget = document.getElementById(idTarget);
6262
if( elTarget ){
63
- var text = elTarget.innerText;
63
+ var text = elTarget.innerText.replace(/^\s+|\s+$/g,'');
6464
var cchLength = parseInt(this.getAttribute("data-copylength"));
6565
if( !isNaN(cchLength) && cchLength>0 ){
6666
text = text.slice(0,cchLength); // Assume single-byte chars.
6767
}
6868
copyTextToClipboard(text);
6969
--- src/copybtn.js
+++ src/copybtn.js
@@ -58,11 +58,11 @@
58 this.style.transition = "opacity 400ms ease-in-out";
59 this.style.opacity = 0;
60 var idTarget = this.getAttribute("data-copytarget");
61 var elTarget = document.getElementById(idTarget);
62 if( elTarget ){
63 var text = elTarget.innerText;
64 var cchLength = parseInt(this.getAttribute("data-copylength"));
65 if( !isNaN(cchLength) && cchLength>0 ){
66 text = text.slice(0,cchLength); // Assume single-byte chars.
67 }
68 copyTextToClipboard(text);
69
--- src/copybtn.js
+++ src/copybtn.js
@@ -58,11 +58,11 @@
58 this.style.transition = "opacity 400ms ease-in-out";
59 this.style.opacity = 0;
60 var idTarget = this.getAttribute("data-copytarget");
61 var elTarget = document.getElementById(idTarget);
62 if( elTarget ){
63 var text = elTarget.innerText.replace(/^\s+|\s+$/g,'');
64 var cchLength = parseInt(this.getAttribute("data-copylength"));
65 if( !isNaN(cchLength) && cchLength>0 ){
66 text = text.slice(0,cchLength); // Assume single-byte chars.
67 }
68 copyTextToClipboard(text);
69

Keyboard Shortcuts

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