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.)
Commit
2e17a063a25575ff8c5062b99ac1811d9ff702da8568d818c7d629c986236746
Parent
2002a508936a758…
2 files changed
+10
-4
+2
-1
+10
-4
| --- src/copybtn.js | ||
| +++ src/copybtn.js | ||
| @@ -1,24 +1,28 @@ | ||
| 1 | 1 | /* Create (if necessary) and initialize a "Copy Text" button <idButton> linked |
| 2 | 2 | ** to the target element <idTarget>. |
| 3 | 3 | ** |
| 4 | 4 | ** 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> | |
| 6 | 8 | ** |
| 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. | |
| 9 | 12 | */ |
| 10 | -function makeCopyButton(idButton,idTarget){ | |
| 13 | +function makeCopyButton(idButton,idTarget,cchLength){ | |
| 11 | 14 | var elButton = document.getElementById(idButton); |
| 12 | 15 | if( !elButton ){ |
| 13 | 16 | elButton = document.createElement("span"); |
| 14 | 17 | elButton.className = "copy-button"; |
| 15 | 18 | elButton.id = idButton; |
| 16 | 19 | } |
| 17 | 20 | elButton.style.transition = ""; |
| 18 | 21 | elButton.style.opacity = 1; |
| 19 | 22 | if( idTarget ) elButton.setAttribute("data-copytarget",idTarget); |
| 23 | + if( cchLength ) elButton.setAttribute("data-copylength",cchLength); | |
| 20 | 24 | elButton.onclick = clickCopyButton; |
| 21 | 25 | return elButton; |
| 22 | 26 | } |
| 23 | 27 | /* The onclick handler for the "Copy Text" button. */ |
| 24 | 28 | var lockCopyText = false; |
| @@ -31,10 +35,12 @@ | ||
| 31 | 35 | this.style.opacity = 0; |
| 32 | 36 | var idTarget = this.getAttribute("data-copytarget"); |
| 33 | 37 | var elTarget = document.getElementById(idTarget); |
| 34 | 38 | if( elTarget ){ |
| 35 | 39 | var text = elTarget.innerText; |
| 40 | + var cchLength = this.getAttribute("data-copylength"); | |
| 41 | + if( cchLength ) text = text.slice(0,cchLength); // Assume single-byte chars. | |
| 36 | 42 | copyTextToClipboard(text); |
| 37 | 43 | } |
| 38 | 44 | setTimeout(function(id){ |
| 39 | 45 | var elButton = document.getElementById(id); |
| 40 | 46 | if( elButton ){ |
| 41 | 47 |
| --- 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 @@ | ||
| 629 | 629 | tooltipObj.style.borderColor = |
| 630 | 630 | tooltipObj.style.color = s.getPropertyValue('color') |
| 631 | 631 | tooltipObj.style.visibility = "hidden" |
| 632 | 632 | tooltipObj.innerHTML = html |
| 633 | 633 | tooltipObj.appendChild(document.createTextNode(' ')); |
| 634 | - tooltipObj.appendChild(makeCopyButton("tooltip-copybtn","tooltip-link")); | |
| 634 | + tooltipObj.appendChild( | |
| 635 | + makeCopyButton("tooltip-copybtn","tooltip-link",0)); | |
| 635 | 636 | tooltipObj.style.display = "inline" |
| 636 | 637 | tooltipObj.style.position = "absolute" |
| 637 | 638 | var x = tooltipInfo.posX + 4 + window.pageXOffset |
| 638 | 639 | - absoluteX(tooltipObj.offsetParent) |
| 639 | 640 | tooltipObj.style.left = x+"px" |
| 640 | 641 |
| --- 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 |