Skip to content

Commit a6f3f17

Browse files
committed
Merge branch 'jn/gitweb-js'
* jn/gitweb-js: gitweb: Make JavaScript ability to adjust timezones configurable gitweb.js: Add UI for selecting common timezone to display dates gitweb: JavaScript ability to adjust time based on timezone gitweb: Unify the way long timestamp is displayed gitweb: Refactor generating of long dates into format_timestamp_html gitweb.js: Provide getElementsByClassName method (if it not exists) gitweb.js: Introduce code to handle cookies from JavaScript gitweb.js: Extract and improve datetime handling gitweb.js: Provide default values for padding in padLeftStr and padLeft gitweb.js: Update and improve comments in JavaScript files gitweb: Split JavaScript for maintability, combining on build
2 parents 229e72d + 2e987f9 commit a6f3f17

File tree

11 files changed

+1023
-241
lines changed

11 files changed

+1023
-241
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
/gitk-git/gitk-wish
164164
/gitweb/GITWEB-BUILD-OPTIONS
165165
/gitweb/gitweb.cgi
166+
/gitweb/static/gitweb.js
166167
/gitweb/static/gitweb.min.*
167168
/test-chmtime
168169
/test-ctype

gitweb/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ ifndef V
8686
endif
8787
endif
8888

89-
all:: gitweb.cgi
89+
all:: gitweb.cgi static/gitweb.js
9090

9191
GITWEB_PROGRAMS = gitweb.cgi
9292

@@ -112,6 +112,18 @@ endif
112112

113113
GITWEB_FILES += static/git-logo.png static/git-favicon.png
114114

115+
# JavaScript files that are composed (concatenated) to form gitweb.js
116+
#
117+
# js/lib/common-lib.js should be always first, then js/lib/*.js,
118+
# then the rest of files; js/gitweb.js should be last (if it exists)
119+
GITWEB_JSLIB_FILES += static/js/lib/common-lib.js
120+
GITWEB_JSLIB_FILES += static/js/lib/datetime.js
121+
GITWEB_JSLIB_FILES += static/js/lib/cookies.js
122+
GITWEB_JSLIB_FILES += static/js/javascript-detection.js
123+
GITWEB_JSLIB_FILES += static/js/adjust-timezone.js
124+
GITWEB_JSLIB_FILES += static/js/blame_incremental.js
125+
126+
115127
GITWEB_REPLACE = \
116128
-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
117129
-e 's|++GIT_BINDIR++|$(bindir)|g' \
@@ -146,6 +158,11 @@ gitweb.cgi: gitweb.perl GITWEB-BUILD-OPTIONS
146158
chmod +x $@+ && \
147159
mv $@+ $@
148160

161+
static/gitweb.js: $(GITWEB_JSLIB_FILES)
162+
$(QUIET_GEN)$(RM) $@ $@+ && \
163+
cat $^ >$@+ && \
164+
mv $@+ $@
165+
149166
### Testing rules
150167

151168
test:

gitweb/gitweb.perl

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,18 @@ sub evaluate_uri {
491491
'override' => 0,
492492
'default' => [0]},
493493

494+
# Enable and configure ability to change common timezone for dates
495+
# in gitweb output via JavaScript. Enabled by default.
496+
# Project specific override is not supported.
497+
'javascript-timezone' => {
498+
'override' => 0,
499+
'default' => [
500+
'local', # default timezone: 'utc', 'local', or '(-|+)HHMM' format,
501+
# or undef to turn off this feature
502+
'gitweb_tz', # name of cookie where to store selected timezone
503+
'datetime', # CSS class used to mark up dates for manipulation
504+
]},
505+
494506
# Syntax highlighting support. This is based on Daniel Svensson's
495507
# and Sham Chukoury's work in gitweb-xmms2.git.
496508
# It requires the 'highlight' program present in $PATH,
@@ -3897,9 +3909,20 @@ sub git_footer_html {
38973909
qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.
38983910
qq! "!. href() .qq!");\n!.
38993911
qq!</script>\n!;
3900-
} elsif (gitweb_check_feature('javascript-actions')) {
3912+
} else {
3913+
my ($jstimezone, $tz_cookie, $datetime_class) =
3914+
gitweb_get_feature('javascript-timezone');
3915+
39013916
print qq!<script type="text/javascript">\n!.
3902-
qq!window.onload = fixLinks;\n!.
3917+
qq!window.onload = function () {\n!;
3918+
if (gitweb_check_feature('javascript-actions')) {
3919+
print qq! fixLinks();\n!;
3920+
}
3921+
if ($jstimezone && $tz_cookie && $datetime_class) {
3922+
print qq! var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
3923+
qq! onloadTZSetup('$jstimezone', tz_cookie, '$datetime_class');\n!;
3924+
}
3925+
print qq!};\n!.
39033926
qq!</script>\n!;
39043927
}
39053928

@@ -4103,22 +4126,25 @@ sub git_print_section {
41034126
print $cgi->end_div;
41044127
}
41054128

4106-
sub print_local_time {
4107-
print format_local_time(@_);
4108-
}
4129+
sub format_timestamp_html {
4130+
my $date = shift;
4131+
my $strtime = $date->{'rfc2822'};
41094132

4110-
sub format_local_time {
4111-
my $localtime = '';
4112-
my %date = @_;
4113-
if ($date{'hour_local'} < 6) {
4114-
$localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4115-
$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
4116-
} else {
4117-
$localtime .= sprintf(" (%02d:%02d %s)",
4118-
$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
4133+
my (undef, undef, $datetime_class) =
4134+
gitweb_get_feature('javascript-timezone');
4135+
if ($datetime_class) {
4136+
$strtime = qq!<span class="$datetime_class">$strtime</span>!;
41194137
}
41204138

4121-
return $localtime;
4139+
my $localtime_format = '(%02d:%02d %s)';
4140+
if ($date->{'hour_local'} < 6) {
4141+
$localtime_format = '(<span class="atnight">%02d:%02d</span> %s)';
4142+
}
4143+
$strtime .= ' ' .
4144+
sprintf($localtime_format,
4145+
$date->{'hour_local'}, $date->{'minute_local'}, $date->{'tz_local'});
4146+
4147+
return $strtime;
41224148
}
41234149

41244150
# Outputs the author name and date in long form
@@ -4131,10 +4157,9 @@ sub git_print_authorship {
41314157
my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
41324158
print "<$tag class=\"author_date\">" .
41334159
format_search_author($author, "author", esc_html($author)) .
4134-
" [$ad{'rfc2822'}";
4135-
print_local_time(%ad) if ($opts{-localtime});
4136-
print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
4137-
. "</$tag>\n";
4160+
" [".format_timestamp_html(\%ad)."]".
4161+
git_get_avatar($co->{'author_email'}, -pad_before => 1) .
4162+
"</$tag>\n";
41384163
}
41394164

41404165
# Outputs table rows containing the full author or committer information,
@@ -4151,16 +4176,16 @@ sub git_print_authorship_rows {
41514176
my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"});
41524177
print "<tr><td>$who</td><td>" .
41534178
format_search_author($co->{"${who}_name"}, $who,
4154-
esc_html($co->{"${who}_name"})) . " " .
4179+
esc_html($co->{"${who}_name"})) . " " .
41554180
format_search_author($co->{"${who}_email"}, $who,
4156-
esc_html("<" . $co->{"${who}_email"} . ">")) .
4181+
esc_html("<" . $co->{"${who}_email"} . ">")) .
41574182
"</td><td rowspan=\"2\">" .
41584183
git_get_avatar($co->{"${who}_email"}, -size => 'double') .
41594184
"</td></tr>\n" .
41604185
"<tr>" .
4161-
"<td></td><td> $wd{'rfc2822'}";
4162-
print_local_time(%wd);
4163-
print "</td>" .
4186+
"<td></td><td>" .
4187+
format_timestamp_html(\%wd) .
4188+
"</td>" .
41644189
"</tr>\n";
41654190
}
41664191
}
@@ -5648,7 +5673,8 @@ sub git_summary {
56485673
"<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
56495674
"<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
56505675
if (defined $cd{'rfc2822'}) {
5651-
print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5676+
print "<tr id=\"metadata_lchange\"><td>last change</td>" .
5677+
"<td>".format_timestamp_html(\%cd)."</td></tr>\n";
56525678
}
56535679

56545680
# use per project git URL list in $projectroot/$project/cloneurl

gitweb/static/gitweb.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,39 @@ div.remote {
586586
display: inline-block;
587587
}
588588

589+
/* JavaScript-based timezone manipulation */
590+
591+
.popup { /* timezone selection UI */
592+
position: absolute;
593+
/* "top: 0; right: 0;" would be better, if not for bugs in browsers */
594+
top: 0; left: 0;
595+
border: 1px solid;
596+
padding: 2px;
597+
background-color: #f0f0f0;
598+
font-style: normal;
599+
color: #000000;
600+
cursor: auto;
601+
}
602+
603+
.close-button { /* close timezone selection UI without selecting */
604+
/* float doesn't work within absolutely positioned container,
605+
* if width of container is not set explicitly */
606+
/* float: right; */
607+
position: absolute;
608+
top: 0px; right: 0px;
609+
border: 1px solid green;
610+
margin: 1px 1px 1px 1px;
611+
padding-bottom: 2px;
612+
width: 12px;
613+
height: 10px;
614+
font-size: 9px;
615+
font-weight: bold;
616+
text-align: center;
617+
background-color: #fff0f0;
618+
cursor: pointer;
619+
}
620+
621+
589622
/* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */
590623

591624
/* Highlighting theme definition: */

gitweb/static/js/README

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
GIT web interface (gitweb) - JavaScript
2+
=======================================
3+
4+
This directory holds JavaScript code used by gitweb (GIT web interface).
5+
Scripts from there would be concatenated together in the order specified
6+
by gitweb/Makefile into gitweb/static/gitweb.js, during building of
7+
gitweb/gitweb.cgi (during gitweb building). The resulting file (or its
8+
minification) would then be installed / deployed together with gitweb.
9+
10+
Scripts in 'lib/' subdirectory compose generic JavaScript library,
11+
providing features required by gitweb but in no way limited to gitweb
12+
only. In the future those scripts could be replaced by some JavaScript
13+
library / framework, like e.g. jQuery, YUI, Prototype, MooTools, Dojo,
14+
ExtJS, Script.aculo.us or SproutCore.
15+
16+
All scripts that manipulate gitweb output should be put outside 'lib/',
17+
directly in this directory ('gitweb/static/js/'). Those scripts would
18+
have to be rewritten if gitweb moves to using some JavaScript library.
19+
20+
See also comments in gitweb/Makefile.

0 commit comments

Comments
 (0)