Fossil SCM

Convenience "copy" button before dates on the /info and /forumpost pages.

drh 2026-04-16 12:52 UTC trunk
Commit e39933757acd4c06ec9f2b72cafe9ee614a2943bc5ee5b07f1c663998d29684d
--- src/copybtn.js
+++ src/copybtn.js
@@ -66,10 +66,12 @@
6666
if( elTarget ){
6767
var text = elTarget.innerText.replace(/^\s+|\s+$/g,"");
6868
var cchLength = parseInt(this.getAttribute("data-copylength"));
6969
if( !isNaN(cchLength) && cchLength>0 ){
7070
text = text.slice(0,cchLength); /* Assume single-byte chars. */
71
+ }else if( /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(text) ){
72
+ text = text.replace(' ', 'T');
7173
}
7274
copyTextToClipboard(text);
7375
}
7476
}
7577
/* Create a temporary <textarea> element and copy the contents to clipboard. */
7678
--- src/copybtn.js
+++ src/copybtn.js
@@ -66,10 +66,12 @@
66 if( elTarget ){
67 var text = elTarget.innerText.replace(/^\s+|\s+$/g,"");
68 var cchLength = parseInt(this.getAttribute("data-copylength"));
69 if( !isNaN(cchLength) && cchLength>0 ){
70 text = text.slice(0,cchLength); /* Assume single-byte chars. */
 
 
71 }
72 copyTextToClipboard(text);
73 }
74 }
75 /* Create a temporary <textarea> element and copy the contents to clipboard. */
76
--- src/copybtn.js
+++ src/copybtn.js
@@ -66,10 +66,12 @@
66 if( elTarget ){
67 var text = elTarget.innerText.replace(/^\s+|\s+$/g,"");
68 var cchLength = parseInt(this.getAttribute("data-copylength"));
69 if( !isNaN(cchLength) && cchLength>0 ){
70 text = text.slice(0,cchLength); /* Assume single-byte chars. */
71 }else if( /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(text) ){
72 text = text.replace(' ', 'T');
73 }
74 copyTextToClipboard(text);
75 }
76 }
77 /* Create a temporary <textarea> element and copy the contents to clipboard. */
78
+6 -1
--- src/forum.c
+++ src/forum.c
@@ -763,10 +763,11 @@
763763
char *zQuery /* Common query string */
764764
){
765765
char *zPosterName; /* Name of user who originally made this post */
766766
char *zEditorName; /* Name of user who provided the current edit */
767767
char *zDate; /* The time/date string */
768
+ char *zDateTag; /* Tag for the time/date text */
768769
char *zHist; /* History query string */
769770
Manifest *pManifest; /* Manifest comprising the current post */
770771
int bPrivate; /* True for posts awaiting moderation */
771772
int bSameUser; /* True if author is also the reader */
772773
int iIndent; /* Indent level */
@@ -809,10 +810,11 @@
809810
}else{
810811
zPosterName = forum_post_display_name(p, pManifest);
811812
zEditorName = zPosterName;
812813
}
813814
zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", p->rDate);
815
+ zDateTag = mprintf("datetag-%d", p->fpid);
814816
if( p->pEditPrev ){
815817
zPosterName = forum_post_display_name(p->pEditHead, 0);
816818
zEditorName = forum_post_display_name(p, pManifest);
817819
zHist = bHist ? "" : zQuery[0]==0 ? "?hist" : "&hist";
818820
@ <h3 class='forumPostHdr'>(%d(p->sid)\
@@ -828,13 +830,16 @@
828830
@ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
829831
}
830832
}else{
831833
zPosterName = forum_post_display_name(p, pManifest);
832834
@ <h3 class='forumPostHdr'>(%d(p->sid))
833
- @ By %s(zPosterName) on %h(zDate)
835
+ @ By %s(zPosterName) on \
836
+ style_copy_button(1, zDateTag, 0, 0, "%h", zDate);
837
+ cgi_printf(" ");
834838
}
835839
fossil_free(zDate);
840
+ fossil_free(zDateTag);
836841
837842
838843
/* If debugging is enabled, link to the artifact page. */
839844
if( g.perm.Debug ){
840845
@ <span class="debug">\
841846
--- src/forum.c
+++ src/forum.c
@@ -763,10 +763,11 @@
763 char *zQuery /* Common query string */
764 ){
765 char *zPosterName; /* Name of user who originally made this post */
766 char *zEditorName; /* Name of user who provided the current edit */
767 char *zDate; /* The time/date string */
 
768 char *zHist; /* History query string */
769 Manifest *pManifest; /* Manifest comprising the current post */
770 int bPrivate; /* True for posts awaiting moderation */
771 int bSameUser; /* True if author is also the reader */
772 int iIndent; /* Indent level */
@@ -809,10 +810,11 @@
809 }else{
810 zPosterName = forum_post_display_name(p, pManifest);
811 zEditorName = zPosterName;
812 }
813 zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", p->rDate);
 
814 if( p->pEditPrev ){
815 zPosterName = forum_post_display_name(p->pEditHead, 0);
816 zEditorName = forum_post_display_name(p, pManifest);
817 zHist = bHist ? "" : zQuery[0]==0 ? "?hist" : "&hist";
818 @ <h3 class='forumPostHdr'>(%d(p->sid)\
@@ -828,13 +830,16 @@
828 @ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
829 }
830 }else{
831 zPosterName = forum_post_display_name(p, pManifest);
832 @ <h3 class='forumPostHdr'>(%d(p->sid))
833 @ By %s(zPosterName) on %h(zDate)
 
 
834 }
835 fossil_free(zDate);
 
836
837
838 /* If debugging is enabled, link to the artifact page. */
839 if( g.perm.Debug ){
840 @ <span class="debug">\
841
--- src/forum.c
+++ src/forum.c
@@ -763,10 +763,11 @@
763 char *zQuery /* Common query string */
764 ){
765 char *zPosterName; /* Name of user who originally made this post */
766 char *zEditorName; /* Name of user who provided the current edit */
767 char *zDate; /* The time/date string */
768 char *zDateTag; /* Tag for the time/date text */
769 char *zHist; /* History query string */
770 Manifest *pManifest; /* Manifest comprising the current post */
771 int bPrivate; /* True for posts awaiting moderation */
772 int bSameUser; /* True if author is also the reader */
773 int iIndent; /* Indent level */
@@ -809,10 +810,11 @@
810 }else{
811 zPosterName = forum_post_display_name(p, pManifest);
812 zEditorName = zPosterName;
813 }
814 zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", p->rDate);
815 zDateTag = mprintf("datetag-%d", p->fpid);
816 if( p->pEditPrev ){
817 zPosterName = forum_post_display_name(p->pEditHead, 0);
818 zEditorName = forum_post_display_name(p, pManifest);
819 zHist = bHist ? "" : zQuery[0]==0 ? "?hist" : "&hist";
820 @ <h3 class='forumPostHdr'>(%d(p->sid)\
@@ -828,13 +830,16 @@
830 @ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
831 }
832 }else{
833 zPosterName = forum_post_display_name(p, pManifest);
834 @ <h3 class='forumPostHdr'>(%d(p->sid))
835 @ By %s(zPosterName) on \
836 style_copy_button(1, zDateTag, 0, 0, "%h", zDate);
837 cgi_printf(" ");
838 }
839 fossil_free(zDate);
840 fossil_free(zDateTag);
841
842
843 /* If debugging is enabled, link to the artifact page. */
844 if( g.perm.Debug ){
845 @ <span class="debug">\
846
+4 -1
--- src/info.c
+++ src/info.c
@@ -1070,11 +1070,14 @@
10701070
@ (Record ID: %d(rid))
10711071
}
10721072
@ </td></tr>
10731073
@ <tr><th>User&nbsp;&amp;&nbsp;Date:</th><td>
10741074
hyperlink_to_user(zUser,zDate," on ");
1075
- hyperlink_to_date(zDate, "</td></tr>");
1075
+ style_copy_button(1, "date-ci", 0, 0,
1076
+ "%z%h</a>", href("%R/timeline?c=%T",zDate), zDate);
1077
+ @ </td></tr>
1078
+ // hyperlink_to_date(zDate, "</td></tr>");
10761079
if( zEComment ){
10771080
@ <tr><th>Original&nbsp;Comment:</th>
10781081
@ <td class="infoComment">%!W(zComment)</td></tr>
10791082
}
10801083
if( fossil_strcmp(zDate, zOrigDate)!=0
10811084
--- src/info.c
+++ src/info.c
@@ -1070,11 +1070,14 @@
1070 @ (Record ID: %d(rid))
1071 }
1072 @ </td></tr>
1073 @ <tr><th>User&nbsp;&amp;&nbsp;Date:</th><td>
1074 hyperlink_to_user(zUser,zDate," on ");
1075 hyperlink_to_date(zDate, "</td></tr>");
 
 
 
1076 if( zEComment ){
1077 @ <tr><th>Original&nbsp;Comment:</th>
1078 @ <td class="infoComment">%!W(zComment)</td></tr>
1079 }
1080 if( fossil_strcmp(zDate, zOrigDate)!=0
1081
--- src/info.c
+++ src/info.c
@@ -1070,11 +1070,14 @@
1070 @ (Record ID: %d(rid))
1071 }
1072 @ </td></tr>
1073 @ <tr><th>User&nbsp;&amp;&nbsp;Date:</th><td>
1074 hyperlink_to_user(zUser,zDate," on ");
1075 style_copy_button(1, "date-ci", 0, 0,
1076 "%z%h</a>", href("%R/timeline?c=%T",zDate), zDate);
1077 @ </td></tr>
1078 // hyperlink_to_date(zDate, "</td></tr>");
1079 if( zEComment ){
1080 @ <tr><th>Original&nbsp;Comment:</th>
1081 @ <td class="infoComment">%!W(zComment)</td></tr>
1082 }
1083 if( fossil_strcmp(zDate, zOrigDate)!=0
1084
--- src/style.c
+++ src/style.c
@@ -497,10 +497,14 @@
497497
** <= 0: Use all of the text
498498
** >= 3: Truncate the text after mxLength bytes.
499499
** 1: Use the "hash-digits" setting as the limit.
500500
** 2: Use the length appropriate for URLs as the limit (defined at
501501
** compile-time by FOSSIL_HASH_DIGITS_URL, defaults to 16).
502
+**
503
+** Note: If the text to be copied is an ISO8601 date-time with a space
504
+** separator between the date and the time, that space is converted to "T"
505
+** for the copy.
502506
*/
503507
char *style_copy_button(
504508
int bOutputCGI, /* Don't return result, but send to cgi_printf(). */
505509
const char *zTargetId, /* HTML id of the text */
506510
int bFlipped, /* True to put copy button after text */
507511
--- src/style.c
+++ src/style.c
@@ -497,10 +497,14 @@
497 ** <= 0: Use all of the text
498 ** >= 3: Truncate the text after mxLength bytes.
499 ** 1: Use the "hash-digits" setting as the limit.
500 ** 2: Use the length appropriate for URLs as the limit (defined at
501 ** compile-time by FOSSIL_HASH_DIGITS_URL, defaults to 16).
 
 
 
 
502 */
503 char *style_copy_button(
504 int bOutputCGI, /* Don't return result, but send to cgi_printf(). */
505 const char *zTargetId, /* HTML id of the text */
506 int bFlipped, /* True to put copy button after text */
507
--- src/style.c
+++ src/style.c
@@ -497,10 +497,14 @@
497 ** <= 0: Use all of the text
498 ** >= 3: Truncate the text after mxLength bytes.
499 ** 1: Use the "hash-digits" setting as the limit.
500 ** 2: Use the length appropriate for URLs as the limit (defined at
501 ** compile-time by FOSSIL_HASH_DIGITS_URL, defaults to 16).
502 **
503 ** Note: If the text to be copied is an ISO8601 date-time with a space
504 ** separator between the date and the time, that space is converted to "T"
505 ** for the copy.
506 */
507 char *style_copy_button(
508 int bOutputCGI, /* Don't return result, but send to cgi_printf(). */
509 const char *zTargetId, /* HTML id of the text */
510 int bFlipped, /* True to put copy button after text */
511

Keyboard Shortcuts

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