[PATCH] Reduce line number bloat, fix hover effect

Peter Wu lekensteyn at gmail.com
Thu Oct 3 12:17:23 CEST 2013


Currently line numbers look like (for blob view and sdiff respectively):

    <a class='no' id='n68' name='n68' href='#n68'>68</a>
    <td class='lineno'><a class='no' href='...#n1' id='n1' name='n1'>1</a></td>

name=".." is unnecessary if the id attribute is set (this even applies
to IE6), so drop it. (aside, in HTML5, the name attribute is gone.)

The line number links can be selected through their parent classes, no
need for another class "no", so drop it too.

For a file with 2000 lines, this yields a saving of 40% (29% gzipped).

While at it, fix the hover effect of line numbers: now the line number
get a black background as was intended.

Signed-off-by: Peter Wu <lekensteyn at gmail.com>
---
 cgit.css    | 6 ++++--
 ui-ssdiff.c | 8 ++++----
 ui-tree.c   | 2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/cgit.css b/cgit.css
index d467c66..71b0b9b 100644
--- a/cgit.css
+++ b/cgit.css
@@ -291,13 +291,15 @@ div#cgit table.blob pre {
 	padding: 0; margin: 0;
 }
 
-div#cgit table.blob a.no, div#cgit table.ssdiff a.no {
+div#cgit table.blob td.linenumbers a,
+div#cgit table.ssdiff td.lineno a {
 	color: gray;
 	text-align: right;
 	text-decoration: none;
 }
 
-div#cgit table.blob a.no a:hover {
+div#cgit table.blob td.linenumbers a:hover,
+div#cgit table.ssdiff td.lineno a:hover {
 	color: black;
 }
 
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
index cbe60bd..08cf513 100644
--- a/ui-ssdiff.c
+++ b/ui-ssdiff.c
@@ -230,9 +230,9 @@ static void print_ssdiff_line(char *class,
 		struct diff_filespec *old_file = cgit_get_current_old_file();
 		char *lineno_str = fmt("n%d", old_line_no);
 		char *id_str = fmt("id=%s#%s", is_null_sha1(old_file->sha1)?"HEAD":sha1_to_hex(old_rev_sha1), lineno_str);
-		html("<td class='lineno'><a class='no' href='");
+		html("<td class='lineno'><a href='");
 		html(cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str));
-		htmlf("' id='%s' name='%s'>%s</a>", lineno_str, lineno_str, lineno_str + 1);
+		htmlf("' id='%s'>%s</a>", lineno_str, lineno_str + 1);
 		html("</td>");
 		htmlf("<td class='%s'>", class);
 	} else if (old_line)
@@ -251,9 +251,9 @@ static void print_ssdiff_line(char *class,
 		struct diff_filespec *new_file = cgit_get_current_new_file();
 		char *lineno_str = fmt("n%d", new_line_no);
 		char *id_str = fmt("id=%s#%s", is_null_sha1(new_file->sha1)?"HEAD":sha1_to_hex(new_rev_sha1), lineno_str);
-		html("<td class='lineno'><a class='no' href='");
+		html("<td class='lineno'><a href='");
 		html(cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str));
-		htmlf("' id='%s' name='%s'>%s</a>", lineno_str, lineno_str, lineno_str + 1);
+		htmlf("' id='%s'>%s</a>", lineno_str, lineno_str + 1);
 		html("</td>");
 		htmlf("<td class='%s'>", class);
 	} else if (new_line)
diff --git a/ui-tree.c b/ui-tree.c
index aa5dee9..9fb9590 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -22,7 +22,7 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
 {
 	unsigned long lineno, idx;
 	const char *numberfmt =
-		"<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
+		"<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
 
 	html("<table summary='blob content' class='blob'>\n");
 
-- 
1.8.4



More information about the CGit mailing list