Fossil SCM

Demonstration of the copybtn.js module beyond tooltips: add a copy button near the full-length hash of check-ins on the /info page, to copy only the hash prefix when clicked.

florian 2019-05-31 16:36 copybtn.js-demonstration
Commit 46f91da1a8d867c6dfa19a694dfed7dfe522d9f6d84f6442c989a98a33151c1a
1 file changed +10 -1
+10 -1
--- src/info.c
+++ src/info.c
@@ -652,10 +652,16 @@
652652
ReCompiled *pRe = 0; /* regex */
653653
const char *zW; /* URL param for ignoring whitespace */
654654
const char *zPage = "vinfo"; /* Page that shows diffs */
655655
const char *zPageHide = "ci"; /* Page that hides diffs */
656656
657
+/* Preprocessor definitions copied from src\printf.c. */
658
+#ifndef FOSSIL_HASH_DIGITS
659
+# define FOSSIL_HASH_DIGITS 10
660
+#endif
661
+ int nDigitHuman = db_get_int("hash-digits", FOSSIL_HASH_DIGITS);
662
+
657663
login_check_credentials();
658664
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
659665
zName = P("name");
660666
rid = name_to_rid_www("name");
661667
if( rid==0 ){
@@ -793,11 +799,14 @@
793799
@ | %z(href("%R/fileage?name=%!S",zUuid))file ages</a>
794800
@ | %z(href("%R/tree?nofiles&type=tree&ci=%!S",zUuid))folders</a>
795801
@ </td>
796802
@ </tr>
797803
798
- @ <tr><th>%s(hname_alg(nUuid)):</th><td>%.32s(zUuid)<wbr>%s(zUuid+32)
804
+ @ <tr><th>%s(hname_alg(nUuid)):</th><td>
805
+ @ <span class="copy-button" id="copy-fullhash" data-copytarget="fullhash"
806
+ @ data-copylength="%d(nDigitHuman)"></span>
807
+ @ <span id="fullhash">%.32s(zUuid)<wbr>%s(zUuid+32)</span>
799808
if( g.perm.Setup ){
800809
@ (Record ID: %d(rid))
801810
}
802811
@ </td></tr>
803812
@ <tr><th>User&nbsp;&amp;&nbsp;Date:</th><td>
804813
--- src/info.c
+++ src/info.c
@@ -652,10 +652,16 @@
652 ReCompiled *pRe = 0; /* regex */
653 const char *zW; /* URL param for ignoring whitespace */
654 const char *zPage = "vinfo"; /* Page that shows diffs */
655 const char *zPageHide = "ci"; /* Page that hides diffs */
656
 
 
 
 
 
 
657 login_check_credentials();
658 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
659 zName = P("name");
660 rid = name_to_rid_www("name");
661 if( rid==0 ){
@@ -793,11 +799,14 @@
793 @ | %z(href("%R/fileage?name=%!S",zUuid))file ages</a>
794 @ | %z(href("%R/tree?nofiles&type=tree&ci=%!S",zUuid))folders</a>
795 @ </td>
796 @ </tr>
797
798 @ <tr><th>%s(hname_alg(nUuid)):</th><td>%.32s(zUuid)<wbr>%s(zUuid+32)
 
 
 
799 if( g.perm.Setup ){
800 @ (Record ID: %d(rid))
801 }
802 @ </td></tr>
803 @ <tr><th>User&nbsp;&amp;&nbsp;Date:</th><td>
804
--- src/info.c
+++ src/info.c
@@ -652,10 +652,16 @@
652 ReCompiled *pRe = 0; /* regex */
653 const char *zW; /* URL param for ignoring whitespace */
654 const char *zPage = "vinfo"; /* Page that shows diffs */
655 const char *zPageHide = "ci"; /* Page that hides diffs */
656
657 /* Preprocessor definitions copied from src\printf.c. */
658 #ifndef FOSSIL_HASH_DIGITS
659 # define FOSSIL_HASH_DIGITS 10
660 #endif
661 int nDigitHuman = db_get_int("hash-digits", FOSSIL_HASH_DIGITS);
662
663 login_check_credentials();
664 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
665 zName = P("name");
666 rid = name_to_rid_www("name");
667 if( rid==0 ){
@@ -793,11 +799,14 @@
799 @ | %z(href("%R/fileage?name=%!S",zUuid))file ages</a>
800 @ | %z(href("%R/tree?nofiles&type=tree&ci=%!S",zUuid))folders</a>
801 @ </td>
802 @ </tr>
803
804 @ <tr><th>%s(hname_alg(nUuid)):</th><td>
805 @ <span class="copy-button" id="copy-fullhash" data-copytarget="fullhash"
806 @ data-copylength="%d(nDigitHuman)"></span>
807 @ <span id="fullhash">%.32s(zUuid)<wbr>%s(zUuid+32)</span>
808 if( g.perm.Setup ){
809 @ (Record ID: %d(rid))
810 }
811 @ </td></tr>
812 @ <tr><th>User&nbsp;&amp;&nbsp;Date:</th><td>
813

Keyboard Shortcuts

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