Fossil SCM

Add the "data-copylength" attribute to control the length of the copied text. (Rationale: Allow copying just the shortened hash prefixes from elements displaying the full-length hashes, because the short forms are preferred when building command-lines or URLs, and because the full-length hashes are already much easier to copy.)

florian 2019-05-30 11:33 tooltip-copyhash
Commit 2e17a063a25575ff8c5062b99ac1811d9ff702da8568d818c7d629c986236746
2 files changed +10 -4 +2 -1
+10 -4
--- src/copybtn.js
+++ src/copybtn.js
@@ -1,24 +1,28 @@
11
/* Create (if necessary) and initialize a "Copy Text" button <idButton> linked
22
** to the target element <idTarget>.
33
**
44
** HTML snippet for statically created buttons:
5
-** <span class="copy-button" id="idButton" data-copytarget="idTarget"></span>
5
+**
6
+** <span class="copy-button" id="idButton"
7
+** data-copytarget="idTarget" data-copylength="cchLength"></span>
68
**
7
-** Note: <idTarget> can be set statically or dynamically, this function does not
8
-** overwrite "data-copytarget" attributes with empty values.
9
+** Note: Both <idTarget> and <cchLength> can be set statically or dynamically,
10
+** i.e. the makeCopyButton() function does not overwrite the "data-copytarget"
11
+** and "data-copylength" attributes with empty/zero values.
912
*/
10
-function makeCopyButton(idButton,idTarget){
13
+function makeCopyButton(idButton,idTarget,cchLength){
1114
var elButton = document.getElementById(idButton);
1215
if( !elButton ){
1316
elButton = document.createElement("span");
1417
elButton.className = "copy-button";
1518
elButton.id = idButton;
1619
}
1720
elButton.style.transition = "";
1821
elButton.style.opacity = 1;
1922
if( idTarget ) elButton.setAttribute("data-copytarget",idTarget);
23
+ if( cchLength ) elButton.setAttribute("data-copylength",cchLength);
2024
elButton.onclick = clickCopyButton;
2125
return elButton;
2226
}
2327
/* The onclick handler for the "Copy Text" button. */
2428
var lockCopyText = false;
@@ -31,10 +35,12 @@
3135
this.style.opacity = 0;
3236
var idTarget = this.getAttribute("data-copytarget");
3337
var elTarget = document.getElementById(idTarget);
3438
if( elTarget ){
3539
var text = elTarget.innerText;
40
+ var cchLength = this.getAttribute("data-copylength");
41
+ if( cchLength ) text = text.slice(0,cchLength); // Assume single-byte chars.
3642
copyTextToClipboard(text);
3743
}
3844
setTimeout(function(id){
3945
var elButton = document.getElementById(id);
4046
if( elButton ){
4147
--- src/copybtn.js
+++ src/copybtn.js
@@ -1,24 +1,28 @@
1 /* Create (if necessary) and initialize a "Copy Text" button <idButton> linked
2 ** to the target element <idTarget>.
3 **
4 ** HTML snippet for statically created buttons:
5 ** <span class="copy-button" id="idButton" data-copytarget="idTarget"></span>
 
 
6 **
7 ** Note: <idTarget> can be set statically or dynamically, this function does not
8 ** overwrite "data-copytarget" attributes with empty values.
 
9 */
10 function makeCopyButton(idButton,idTarget){
11 var elButton = document.getElementById(idButton);
12 if( !elButton ){
13 elButton = document.createElement("span");
14 elButton.className = "copy-button";
15 elButton.id = idButton;
16 }
17 elButton.style.transition = "";
18 elButton.style.opacity = 1;
19 if( idTarget ) elButton.setAttribute("data-copytarget",idTarget);
 
20 elButton.onclick = clickCopyButton;
21 return elButton;
22 }
23 /* The onclick handler for the "Copy Text" button. */
24 var lockCopyText = false;
@@ -31,10 +35,12 @@
31 this.style.opacity = 0;
32 var idTarget = this.getAttribute("data-copytarget");
33 var elTarget = document.getElementById(idTarget);
34 if( elTarget ){
35 var text = elTarget.innerText;
 
 
36 copyTextToClipboard(text);
37 }
38 setTimeout(function(id){
39 var elButton = document.getElementById(id);
40 if( elButton ){
41
--- src/copybtn.js
+++ src/copybtn.js
@@ -1,24 +1,28 @@
1 /* Create (if necessary) and initialize a "Copy Text" button <idButton> linked
2 ** to the target element <idTarget>.
3 **
4 ** HTML snippet for statically created buttons:
5 **
6 ** <span class="copy-button" id="idButton"
7 ** data-copytarget="idTarget" data-copylength="cchLength"></span>
8 **
9 ** Note: Both <idTarget> and <cchLength> can be set statically or dynamically,
10 ** i.e. the makeCopyButton() function does not overwrite the "data-copytarget"
11 ** and "data-copylength" attributes with empty/zero values.
12 */
13 function makeCopyButton(idButton,idTarget,cchLength){
14 var elButton = document.getElementById(idButton);
15 if( !elButton ){
16 elButton = document.createElement("span");
17 elButton.className = "copy-button";
18 elButton.id = idButton;
19 }
20 elButton.style.transition = "";
21 elButton.style.opacity = 1;
22 if( idTarget ) elButton.setAttribute("data-copytarget",idTarget);
23 if( cchLength ) elButton.setAttribute("data-copylength",cchLength);
24 elButton.onclick = clickCopyButton;
25 return elButton;
26 }
27 /* The onclick handler for the "Copy Text" button. */
28 var lockCopyText = false;
@@ -31,10 +35,12 @@
35 this.style.opacity = 0;
36 var idTarget = this.getAttribute("data-copytarget");
37 var elTarget = document.getElementById(idTarget);
38 if( elTarget ){
39 var text = elTarget.innerText;
40 var cchLength = this.getAttribute("data-copylength");
41 if( cchLength ) text = text.slice(0,cchLength); // Assume single-byte chars.
42 copyTextToClipboard(text);
43 }
44 setTimeout(function(id){
45 var elButton = document.getElementById(id);
46 if( elButton ){
47
+2 -1
--- src/graph.js
+++ src/graph.js
@@ -629,11 +629,12 @@
629629
tooltipObj.style.borderColor =
630630
tooltipObj.style.color = s.getPropertyValue('color')
631631
tooltipObj.style.visibility = "hidden"
632632
tooltipObj.innerHTML = html
633633
tooltipObj.appendChild(document.createTextNode(' '));
634
- tooltipObj.appendChild(makeCopyButton("tooltip-copybtn","tooltip-link"));
634
+ tooltipObj.appendChild(
635
+ makeCopyButton("tooltip-copybtn","tooltip-link",0));
635636
tooltipObj.style.display = "inline"
636637
tooltipObj.style.position = "absolute"
637638
var x = tooltipInfo.posX + 4 + window.pageXOffset
638639
- absoluteX(tooltipObj.offsetParent)
639640
tooltipObj.style.left = x+"px"
640641
--- src/graph.js
+++ src/graph.js
@@ -629,11 +629,12 @@
629 tooltipObj.style.borderColor =
630 tooltipObj.style.color = s.getPropertyValue('color')
631 tooltipObj.style.visibility = "hidden"
632 tooltipObj.innerHTML = html
633 tooltipObj.appendChild(document.createTextNode(' '));
634 tooltipObj.appendChild(makeCopyButton("tooltip-copybtn","tooltip-link"));
 
635 tooltipObj.style.display = "inline"
636 tooltipObj.style.position = "absolute"
637 var x = tooltipInfo.posX + 4 + window.pageXOffset
638 - absoluteX(tooltipObj.offsetParent)
639 tooltipObj.style.left = x+"px"
640
--- src/graph.js
+++ src/graph.js
@@ -629,11 +629,12 @@
629 tooltipObj.style.borderColor =
630 tooltipObj.style.color = s.getPropertyValue('color')
631 tooltipObj.style.visibility = "hidden"
632 tooltipObj.innerHTML = html
633 tooltipObj.appendChild(document.createTextNode(' '));
634 tooltipObj.appendChild(
635 makeCopyButton("tooltip-copybtn","tooltip-link",0));
636 tooltipObj.style.display = "inline"
637 tooltipObj.style.position = "absolute"
638 var x = tooltipInfo.posX + 4 + window.pageXOffset
639 - absoluteX(tooltipObj.offsetParent)
640 tooltipObj.style.left = x+"px"
641

Keyboard Shortcuts

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