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
This commit is contained in:
Junio C Hamano
2011-05-26 10:31:57 -07:00
11 changed files with 1023 additions and 241 deletions

View File

@ -491,6 +491,18 @@ our %feature = (
'override' => 0,
'default' => [0]},
# Enable and configure ability to change common timezone for dates
# in gitweb output via JavaScript. Enabled by default.
# Project specific override is not supported.
'javascript-timezone' => {
'override' => 0,
'default' => [
'local', # default timezone: 'utc', 'local', or '(-|+)HHMM' format,
# or undef to turn off this feature
'gitweb_tz', # name of cookie where to store selected timezone
'datetime', # CSS class used to mark up dates for manipulation
]},
# Syntax highlighting support. This is based on Daniel Svensson's
# and Sham Chukoury's work in gitweb-xmms2.git.
# It requires the 'highlight' program present in $PATH,
@ -3897,9 +3909,20 @@ sub git_footer_html {
qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.
qq! "!. href() .qq!");\n!.
qq!</script>\n!;
} elsif (gitweb_check_feature('javascript-actions')) {
} else {
my ($jstimezone, $tz_cookie, $datetime_class) =
gitweb_get_feature('javascript-timezone');
print qq!<script type="text/javascript">\n!.
qq!window.onload = fixLinks;\n!.
qq!window.onload = function () {\n!;
if (gitweb_check_feature('javascript-actions')) {
print qq! fixLinks();\n!;
}
if ($jstimezone && $tz_cookie && $datetime_class) {
print qq! var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
qq! onloadTZSetup('$jstimezone', tz_cookie, '$datetime_class');\n!;
}
print qq!};\n!.
qq!</script>\n!;
}
@ -4103,22 +4126,25 @@ sub git_print_section {
print $cgi->end_div;
}
sub print_local_time {
print format_local_time(@_);
}
sub format_timestamp_html {
my $date = shift;
my $strtime = $date->{'rfc2822'};
sub format_local_time {
my $localtime = '';
my %date = @_;
if ($date{'hour_local'} < 6) {
$localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
} else {
$localtime .= sprintf(" (%02d:%02d %s)",
$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
my (undef, undef, $datetime_class) =
gitweb_get_feature('javascript-timezone');
if ($datetime_class) {
$strtime = qq!<span class="$datetime_class">$strtime</span>!;
}
return $localtime;
my $localtime_format = '(%02d:%02d %s)';
if ($date->{'hour_local'} < 6) {
$localtime_format = '(<span class="atnight">%02d:%02d</span> %s)';
}
$strtime .= ' ' .
sprintf($localtime_format,
$date->{'hour_local'}, $date->{'minute_local'}, $date->{'tz_local'});
return $strtime;
}
# Outputs the author name and date in long form
@ -4131,10 +4157,9 @@ sub git_print_authorship {
my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
print "<$tag class=\"author_date\">" .
format_search_author($author, "author", esc_html($author)) .
" [$ad{'rfc2822'}";
print_local_time(%ad) if ($opts{-localtime});
print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
. "</$tag>\n";
" [".format_timestamp_html(\%ad)."]".
git_get_avatar($co->{'author_email'}, -pad_before => 1) .
"</$tag>\n";
}
# Outputs table rows containing the full author or committer information,
@ -4151,16 +4176,16 @@ sub git_print_authorship_rows {
my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"});
print "<tr><td>$who</td><td>" .
format_search_author($co->{"${who}_name"}, $who,
esc_html($co->{"${who}_name"})) . " " .
esc_html($co->{"${who}_name"})) . " " .
format_search_author($co->{"${who}_email"}, $who,
esc_html("<" . $co->{"${who}_email"} . ">")) .
esc_html("<" . $co->{"${who}_email"} . ">")) .
"</td><td rowspan=\"2\">" .
git_get_avatar($co->{"${who}_email"}, -size => 'double') .
"</td></tr>\n" .
"<tr>" .
"<td></td><td> $wd{'rfc2822'}";
print_local_time(%wd);
print "</td>" .
"<td></td><td>" .
format_timestamp_html(\%wd) .
"</td>" .
"</tr>\n";
}
}
@ -5648,7 +5673,8 @@ sub git_summary {
"<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
"<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
if (defined $cd{'rfc2822'}) {
print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
print "<tr id=\"metadata_lchange\"><td>last change</td>" .
"<td>".format_timestamp_html(\%cd)."</td></tr>\n";
}
# use per project git URL list in $projectroot/$project/cloneurl