From da3f7ea17dbc244dc7cf77ba32c2b41590abe641 Mon Sep 17 00:00:00 2001 From: Anthony Ryan Date: Mon, 2 Jun 2014 09:02:24 -0400 Subject: [PATCH] Shift table stlying details onto the client There is almost universal support for the CSS3 :nth-child() pseudo-selector. We're shifting the responsibility for labeling even and odd rows to the browser. --- ngx_http_fancyindex_module.c | 15 ++++----------- template.h | 4 ++-- template.html | 10 +++++----- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/ngx_http_fancyindex_module.c b/ngx_http_fancyindex_module.c index d6ede4b..2ec239e 100644 --- a/ngx_http_fancyindex_module.c +++ b/ngx_http_fancyindex_module.c @@ -569,12 +569,12 @@ make_content_buf( * Genearated table rows are as follows, unneeded whitespace * is stripped out: * - * + * * fname * sizedate * */ - len += ngx_sizeof_ssz("") @@ -661,7 +661,7 @@ make_content_buf( /* "Parent dir" entry, always first */ b->last = ngx_cpymem_ssz(b->last, - "" + "" "last = ngx_cpymem(b->last, @@ -676,14 +676,7 @@ make_content_buf( /* Entries for directories and files */ for (i = 0; i < entries.nelts; i++) { - static const char _evenodd[] = { 'e', 'o' }; - b->last = ngx_cpymem_ssz(b->last, "last++ = _evenodd[i & 0x01]; - /* - * Alternative implementation: - * *b->last++ = (i & 0x01) ? 'e' : 'o'; - */ - b->last = ngx_cpymem_ssz(b->last, "\">last = ngx_cpymem_ssz(b->last, "last, diff --git a/template.h b/template.h index e5faf9a..8375a1f 100644 --- a/template.h +++ b/template.h @@ -13,7 +13,7 @@ static const u_char t01_head1[] = "" "font-family:\"Bitstream Vera Sans\",\"Lucida Grande\"," "\"Lucida Sans Unicode\",Lucidux,Verdana,Lucida,sans-serif;" "}" -"tr.e {" +"tr:nth-child(even) {" "background:#f4f4f4;" "}" "th,td {" @@ -75,7 +75,7 @@ static const u_char t06_list1[] = "" "" ; static const u_char t_parentdir_entry[] = "" -"" +"" "Parent directory/" "-" "-" diff --git a/template.html b/template.html index cccafdf..eb0a40d 100644 --- a/template.html +++ b/template.html @@ -12,7 +12,7 @@ font-family:"Bitstream Vera Sans","Lucida Grande", "Lucida Sans Unicode",Lucidux,Verdana,Lucida,sans-serif; } - tr.e { + tr:nth-child(even) { background:#f4f4f4; } th,td { @@ -72,24 +72,24 @@ - + Parent directory/ - - - + test file 1 123kB date - + test file 2 321MB date - + test file 3 666 date