Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Tweaks to the "Copy Button". |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
8ee5e55e3c2baac570baadc3d567fe0b |
| User & Date: | drh 2019-06-05 20:08:09.709 |
Context
|
2019-06-05
| ||
| 20:15 | Since the /info page is now reachable by double-clicking on the graph node, change the timestamp to be a link to the general /timeline page around that particular time. ... (check-in: 036c854da3 user: drh tags: trunk) | |
| 20:08 | Tweaks to the "Copy Button". ... (check-in: 8ee5e55e3c user: drh tags: trunk) | |
| 19:45 | Update the built-in SQLite to the latest 3.29.0 alpha. ... (check-in: 9c128d2e89 user: drh tags: trunk) | |
| 08:26 | Make sure there's any graph elements, before accessing their properties (applies to timelines for tickets, wiki pages, or forum posts). ... (Closed-Leaf check-in: 6678870734 user: florian tags: copybtn.js-tweaks) | |
Changes
Changes to src/copybtn.js.
1 2 3 4 | /* Manage "Copy Buttons" linked to target elements, to copy the text (or, parts ** thereof) of the target elements to the clipboard. ** ** Newly created buttons are <span> elements with an SVG background icon, | | > | | | > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* Manage "Copy Buttons" linked to target elements, to copy the text (or, parts
** thereof) of the target elements to the clipboard.
**
** Newly created buttons are <span> elements with an SVG background icon,
** defined by the "copy-button" class in the default CSS style sheet, and are
** assigned the element ID "copy-<idTarget>".
**
** To simplify customization, the only properties modified for HTML-defined
** buttons are the "onclick" handler, and the "transition" and "opacity" styles
** (used for animation).
**
** For HTML-defined buttons, either initCopyButtonById(), or initCopyButton(),
** needs to be called to attach the "onclick" handler (done automatically from
** a handler attached to the "DOMContentLoaded" event).
**
** The initialization functions do not overwrite the "data-copytarget" and
** "data-copylength" attributes with empty or null values for <idTarget> and
** <cchLength>, respectively. Set <cchLength> to "-1" to explicitly remove the
** previous copy length limit.
**
** HTML snippet for statically created buttons:
**
** <span class="copy-button" id="copy-<idTarget>"
** data-copytarget="<idTarget>" data-copylength="<cchLength>"></span>
*/
function makeCopyButton(idTarget,bFlipped,cchLength){
var elButton = document.createElement("span");
elButton.className = "copy-button";
if( bFlipped ) elButton.className += " copy-button-flipped";
elButton.id = "copy-" + idTarget;
initCopyButton(elButton,idTarget,cchLength);
return elButton;
}
function initCopyButtonById(idButton,idTarget,cchLength){
var elButton = document.getElementById(idButton);
if( elButton ) initCopyButton(elButton,idTarget,cchLength);
return elButton;
|
| ︙ | ︙ |
Changes to src/default_css.txt.
| ︙ | ︙ | |||
769 770 771 772 773 774 775 |
label {
white-space: nowrap;
}
.copy-button {
display: inline-block;
width: 14px;
height: 14px;
| > | > > > > > | 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
label {
white-space: nowrap;
}
.copy-button {
display: inline-block;
width: 14px;
height: 14px;
//Note: .24em is slightly smaller than the average width of a normal space.
margin: -2px .24em 0 0;
padding: 0;
border: 0;
vertical-align: middle;
//Note: the mkcss utility does not support line breaks in data URIs.
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath style='fill: black; opacity:0' d='M 14 14 H 0 V 0 h 14 v 14 z'/%3E%3Cpath style='fill:rgb(240,240,240)' d='M 1 0 h 6.6 l 2 2 h 1 l 3.4 3.4 v 8.6 h -10 v -2 h -3 z'/%3E%3Cpath style='fill:rgb(64,64,64)' d='M 2 1 h 5 l 3 3 v 7 h -8 z'/%3E%3Cpath style='fill:rgb(248,248,248)' d='M 3 2 h 3.6 l 2.4 2.4 v 5.6 h -6 z'/%3E%3Cpath style='fill:rgb(80,128,208)' d='M 4 5 h 4 v 1 h -4 z m 0 2 h 4 v 1 h -4 z'/%3E%3Cpath style='fill:rgb(64,64,64)' d='M 5 3 h 5 l 3 3 v 7 h -8 z'/%3E%3Cpath style='fill:rgb(248,248,248)' d='M 10 4.4 v 1.6 h 1.6 z m -4 -0.6 h 3 v 3 h -3 z m 0 3 h 6 v 5.4 h -6 z'/%3E%3Cpath style='fill:rgb(80,128,208)' d='M 7 8 h 4 v 1 h -4 z m 0 2 h 4 v 1 h -4 z'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: center;
cursor: pointer;
}
.copy-button-flipped {
//Note: .16em is suitable for element grouping.
margin-left: .16em;
margin-right: 0;
}
|
Changes to src/graph.js.
| ︙ | ︙ | |||
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
ixHover: -1, /* The id of the element with the mouse. */
ixActive: -1, /* The id of the element with the tooltip. */
nodeHover: null, /* Graph node under mouse when ixHover==-2 */
posX: 0, posY: 0 /* The last mouse position. */
};
/* Functions used to control the tooltip popup and its timer */
function hideGraphTooltip(){
stopCloseTimer();
tooltipObj.style.display = "none";
tooltipInfo.ixActive = -1;
}
document.body.onunload = hideGraphTooltip
function stopDwellTimer(){
if (tooltipInfo.idTimer != 0) {
| > > > > > > > > | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
ixHover: -1, /* The id of the element with the mouse. */
ixActive: -1, /* The id of the element with the tooltip. */
nodeHover: null, /* Graph node under mouse when ixHover==-2 */
posX: 0, posY: 0 /* The last mouse position. */
};
/* Functions used to control the tooltip popup and its timer */
function onKeyDown(event){
var key = event.which || event.keyCode;
if( key==27 ){
event.stopPropagation();
hideGraphTooltip();
}
}
function hideGraphTooltip(){
document.removeEventListener('keydown',onKeyDown,/* useCapture == */true);
stopCloseTimer();
tooltipObj.style.display = "none";
tooltipInfo.ixActive = -1;
}
document.body.onunload = hideGraphTooltip
function stopDwellTimer(){
if (tooltipInfo.idTimer != 0) {
|
| ︙ | ︙ | |||
555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
}
function dblclickOnNode(e){
var p = tx.rowinfo[parseInt(this.id.match(/\d+$/)[0], 10)-tx.iTopRow];
window.location.href = tx.baseUrl+"/info/"+p.h
e.stopPropagation()
}
function findTxIndex(e){
/* Look at all the graph elements. If any graph elements that is near
** the click-point "e" and has a "data-ix" attribute, then return
** the value of that attribute. Otherwise return -1 */
var x = e.clientX + window.pageXOffset - absoluteX(canvasDiv);
var y = e.clientY + window.pageYOffset - absoluteY(canvasDiv);
var aNode = canvasDiv.childNodes
var nNode = aNode.length;
| > | 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
}
function dblclickOnNode(e){
var p = tx.rowinfo[parseInt(this.id.match(/\d+$/)[0], 10)-tx.iTopRow];
window.location.href = tx.baseUrl+"/info/"+p.h
e.stopPropagation()
}
function findTxIndex(e){
if( !tx.rowinfo ) return -1;
/* Look at all the graph elements. If any graph elements that is near
** the click-point "e" and has a "data-ix" attribute, then return
** the value of that attribute. Otherwise return -1 */
var x = e.clientX + window.pageXOffset - absoluteX(canvasDiv);
var y = e.clientY + window.pageYOffset - absoluteY(canvasDiv);
var aNode = canvasDiv.childNodes
var nNode = aNode.length;
|
| ︙ | ︙ | |||
626 627 628 629 630 631 632 |
}else{
tooltipObj.style.backgroundColor = s.getPropertyValue('background-color')
}
tooltipObj.style.borderColor =
tooltipObj.style.color = s.getPropertyValue('color')
tooltipObj.style.visibility = "hidden"
tooltipObj.innerHTML = html
| < | < > | 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
}else{
tooltipObj.style.backgroundColor = s.getPropertyValue('background-color')
}
tooltipObj.style.borderColor =
tooltipObj.style.color = s.getPropertyValue('color')
tooltipObj.style.visibility = "hidden"
tooltipObj.innerHTML = html
tooltipObj.appendChild(makeCopyButton("tooltip-link",true,0));
tooltipObj.style.display = "inline"
tooltipObj.style.position = "absolute"
var x = tooltipInfo.posX + 4 + window.pageXOffset
- absoluteX(tooltipObj.offsetParent)
tooltipObj.style.left = x+"px"
var y = tooltipInfo.posY + window.pageYOffset
- tooltipObj.clientHeight - 4
- absoluteY(tooltipObj.offsetParent)
tooltipObj.style.top = y+"px"
tooltipObj.style.visibility = "visible"
document.addEventListener('keydown',onKeyDown,/* useCapture == */true);
}else{
hideGraphTooltip()
}
}
function dblclickOnGraph(e){
var ix = findTxIndex(e);
hideGraphTooltip()
|
| ︙ | ︙ |
Changes to src/info.c.
| ︙ | ︙ | |||
761 762 763 764 765 766 767 |
db_prepare(&q2,"SELECT substr(tag.tagname,5) FROM tagxref, tag "
" WHERE rid=%d AND tagtype>0 "
" AND tag.tagid=tagxref.tagid "
" AND +tag.tagname GLOB 'sym-*'", rid);
while( db_step(&q2)==SQLITE_ROW ){
const char *zTagName = db_column_text(&q2, 0);
if( fossil_strcmp(zTagName,zBrName)==0 ){
| | | | | | 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 |
db_prepare(&q2,"SELECT substr(tag.tagname,5) FROM tagxref, tag "
" WHERE rid=%d AND tagtype>0 "
" AND tag.tagid=tagxref.tagid "
" AND +tag.tagname GLOB 'sym-*'", rid);
while( db_step(&q2)==SQLITE_ROW ){
const char *zTagName = db_column_text(&q2, 0);
if( fossil_strcmp(zTagName,zBrName)==0 ){
@ | <span class="copy-button" id="copy-name-br"
@ data-copytarget="name-br" data-copylength="0">
@ </span><span id="name-br"><!--
@ -->%z(href("%R/timeline?r=%T&unhide",zTagName))%h(zTagName)</a>
@ </span>
if( wiki_tagid2("branch",zTagName)!=0 ){
blob_appendf(&wiki_read_links, " | %z%h</a>",
href("%R/wiki?name=branch/%h",zTagName), zTagName);
}else if( g.perm.Write && g.perm.WrWiki ){
blob_appendf(&wiki_add_links, " | %z%h</a>",
href("%R/wikiedit?name=branch/%h",zTagName), zTagName);
|
| ︙ | ︙ | |||
796 797 798 799 800 801 802 |
@ %z(href("%R/tree?ci=%!S",zUuid))files</a>
@ | %z(href("%R/fileage?name=%!S",zUuid))file ages</a>
@ | %z(href("%R/tree?nofiles&type=tree&ci=%!S",zUuid))folders</a>
@ </td>
@ </tr>
@ <tr><th>%s(hname_alg(nUuid)):</th><td>
| | | | | 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 |
@ %z(href("%R/tree?ci=%!S",zUuid))files</a>
@ | %z(href("%R/fileage?name=%!S",zUuid))file ages</a>
@ | %z(href("%R/tree?nofiles&type=tree&ci=%!S",zUuid))folders</a>
@ </td>
@ </tr>
@ <tr><th>%s(hname_alg(nUuid)):</th><td>
@ <span class="copy-button" id="copy-hash-ci"
@ data-copytarget="hash-ci" data-copylength="%d(hash_digits(1))">
@ </span><span id="hash-ci">%.32s(zUuid)<wbr>%s(zUuid+32)</span>
if( g.perm.Setup ){
@ (Record ID: %d(rid))
}
@ </td></tr>
@ <tr><th>User & Date:</th><td>
hyperlink_to_user(zUser,zDate," on ");
hyperlink_to_date(zDate, "</td></tr>");
|
| ︙ | ︙ | |||
1917 1918 1919 1920 1921 1922 1923 1924 1925 |
style_submenu_element("Unshun", "%s/shun?accept=%s&sub=1#delshun",
g.zTop, zUuid);
}else{
style_submenu_element("Shun", "%s/shun?shun=%s#addshun", g.zTop, zUuid);
}
}
style_header("Hex Artifact Content");
zUuid = db_text("?","SELECT uuid FROM blob WHERE rid=%d", rid);
if( g.perm.Setup ){
| > > > > | | | 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 |
style_submenu_element("Unshun", "%s/shun?accept=%s&sub=1#delshun",
g.zTop, zUuid);
}else{
style_submenu_element("Shun", "%s/shun?shun=%s#addshun", g.zTop, zUuid);
}
}
style_header("Hex Artifact Content");
style_copy_button();
zUuid = db_text("?","SELECT uuid FROM blob WHERE rid=%d", rid);
@ <h2>Artifact
@ <span class="copy-button" id="copy-hash-ar"
@ data-copytarget="hash-ar" data-copylength="%d(hash_digits(1))">
if( g.perm.Setup ){
@ </span><span id="hash-ar">%s(zUuid)</span> (%d(rid)):</h2>
}else{
@ </span><span id="hash-ar">%s(zUuid)</span>:</h2>
}
blob_zero(&downloadName);
if( P("verbose")!=0 ) objdescFlags |= OBJDESC_DETAIL;
object_description(rid, objdescFlags, &downloadName);
style_submenu_element("Download", "%s/raw/%T?name=%s",
g.zTop, blob_str(&downloadName), zUuid);
@ <hr />
|
| ︙ | ︙ | |||
2190 2191 2192 2193 2194 2195 2196 |
zUuid = db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid);
if( isFile ){
@ <h2>Latest version of file '%h(zName)':</h2>
style_submenu_element("Artifact", "%R/artifact/%S", zUuid);
}else{
style_copy_button();
@ <h2>Artifact
| | | | | | 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 |
zUuid = db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid);
if( isFile ){
@ <h2>Latest version of file '%h(zName)':</h2>
style_submenu_element("Artifact", "%R/artifact/%S", zUuid);
}else{
style_copy_button();
@ <h2>Artifact
@ <span class="copy-button" id="copy-hash-ar"
@ data-copytarget="hash-ar" data-copylength="%d(hash_digits(1))">
if( g.perm.Setup ){
@ </span><span id="hash-ar">%s(zUuid)</span> (%d(rid)):</h2>
}else{
@ </span><span id="hash-ar">%s(zUuid)</span>:</h2>
}
}
blob_zero(&downloadName);
asText = P("txt")!=0;
if( asText ) objdescFlags &= ~OBJDESC_BASE;
objType = object_description(rid, objdescFlags, &downloadName);
if( !descOnly && P("download")!=0 ){
|
| ︙ | ︙ |
Changes to src/th_main.c.
| ︙ | ︙ | |||
990 991 992 993 994 995 996 |
sendText("</select>", -1, 0);
Th_Free(interp, azElem);
}
return TH_OK;
}
/*
| | > > | | > > > | | | > | | | | | | | < | | | | > > > > > > > > > > > > > | 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
sendText("</select>", -1, 0);
Th_Free(interp, azElem);
}
return TH_OK;
}
/*
** TH1 command: copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?
**
** Output TEXT with a click-to-copy button next to it. Loads the copybtn.js
** Javascript module, and generates HTML elements with the following IDs:
**
** TARGETID: The <span> wrapper around TEXT.
** copy-TARGETID: The <span> for the copy button.
**
** If the FLIPPED argument is non-zero, the copy button is displayed after TEXT.
**
** The optional COPYLENGTH argument defines the length of the substring of TEXT
** copied to clipboard:
**
** <= 0: No limit (default if the argument is omitted).
** >= 3: Truncate TEXT after COPYLENGTH (single-byte) characters.
** 1: Use the "hash-digits" setting as the limit.
** 2: Use the length appropriate for URLs as the limit (defined at
** compile-time by FOSSIL_HASH_DIGITS_URL, defaults to 16).
*/
static int copybtnCmd(
Th_Interp *interp,
void *p,
int argc,
const char **argv,
int *argl
){
if( argc!=4 && argc!=5 ){
return Th_WrongNumArgs(interp,
"copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?");
}
if( enableOutput ){
int flipped = 0;
int copylength = 0;
char *zTargetId, *zText, *zResult;
if( Th_ToInt(interp, argv[2], argl[2], &flipped) ) return TH_ERROR;
if( argc==5 ){
if( Th_ToInt(interp, argv[4], argl[4], ©length) ) return TH_ERROR;
}
if( copylength==1 ) copylength = hash_digits(0);
else if( copylength==2 ) copylength = hash_digits(1);
zTargetId = htmlize((char*)argv[1], argl[1]);
zText = htmlize((char*)argv[3], argl[3]);
if( !flipped ){
zResult = mprintf(
"<span "
"class=\"copy-button\" "
"id=\"copy-%s\" "
"data-copytarget=\"%s\" "
"data-copylength=\"%d\">"
"</span>"
"<span id=\"%s\">"
"%s"
"</span>",
zTargetId, zTargetId, copylength, zTargetId, zText);
}else{
zResult = mprintf(
"<span id=\"%s\">"
"%s"
"</span>"
"<span "
"class=\"copy-button copy-button-flipped\" "
"id=\"copy-%s\" "
"data-copytarget=\"%s\" "
"data-copylength=\"%d\">"
"</span>",
zTargetId, zText, zTargetId, zTargetId, copylength);
}
free(zTargetId);
free(zText);
style_copy_button();
sendText(zResult, -1, 0);
free(zResult);
}
return TH_OK;
|
| ︙ | ︙ |
Changes to src/tktsetup.c.
| ︙ | ︙ | |||
445 446 447 448 449 450 451 |
static const char zDefaultView[] =
@ <table cellpadding="5">
@ <tr><td class="tktDspLabel">Ticket UUID:</td>
@ <th1>
@ if {[info exists tkt_uuid]} {
@ html "<td class='tktDspValue' colspan='3'>"
| | | 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
static const char zDefaultView[] =
@ <table cellpadding="5">
@ <tr><td class="tktDspLabel">Ticket UUID:</td>
@ <th1>
@ if {[info exists tkt_uuid]} {
@ html "<td class='tktDspValue' colspan='3'>"
@ copybtn hash-tk 0 $tkt_uuid 1
@ if {[hascap s]} {
@ html " ($tkt_id)"
@ }
@ html "</td></tr>\n"
@ } else {
@ if {[hascap s]} {
@ html "<td class='tktDspValue' colspan='3'>Deleted "
|
| ︙ | ︙ |
Changes to www/th1.md.
| ︙ | ︙ | |||
279 280 281 282 283 284 285 | selected value. TEXT-LIST is a list of possible values for the combobox. NUMLINES is 1 for a true combobox. If NUMLINES is greater than one then the display is a listbox with the number of lines given. <a name="copybtn"></a>TH1 copybtn Command ----------------------------------------- | | > > | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | selected value. TEXT-LIST is a list of possible values for the combobox. NUMLINES is 1 for a true combobox. If NUMLINES is greater than one then the display is a listbox with the number of lines given. <a name="copybtn"></a>TH1 copybtn Command ----------------------------------------- * copybtn TARGETID FLIPPED TEXT ?COPYLENGTH? Output TEXT with a click-to-copy button next to it. Loads the copybtn.js Javascript module, and generates HTML elements with the following IDs: * TARGETID: The `<span>` wrapper around TEXT. * copy-TARGETID: The `<span>` for the copy button. If the FLIPPED argument is non-zero, the copy button is displayed after TEXT. The optional COPYLENGTH argument defines the length of the substring of TEXT copied to clipboard: * <= 0: No limit (default if the argument is omitted). * >= 3: Truncate TEXT after COPYLENGTH (single-byte) characters. * 1: Use the "hash-digits" setting as the limit. |
| ︙ | ︙ |