Skip to content

Commit

Permalink
Merge branch 'jn/gitweb-js'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed May 26, 2011
2 parents 229e72d + 2e987f9 commit a6f3f17
Show file tree
Hide file tree
Showing 11 changed files with 1,023 additions and 241 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
/gitk-git/gitk-wish
/gitweb/GITWEB-BUILD-OPTIONS
/gitweb/gitweb.cgi
/gitweb/static/gitweb.js
/gitweb/static/gitweb.min.*
/test-chmtime
/test-ctype
Expand Down
19 changes: 18 additions & 1 deletion gitweb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ifndef V
endif
endif

all:: gitweb.cgi
all:: gitweb.cgi static/gitweb.js

GITWEB_PROGRAMS = gitweb.cgi

Expand All @@ -112,6 +112,18 @@ endif

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

# JavaScript files that are composed (concatenated) to form gitweb.js
#
# js/lib/common-lib.js should be always first, then js/lib/*.js,
# then the rest of files; js/gitweb.js should be last (if it exists)
GITWEB_JSLIB_FILES += static/js/lib/common-lib.js
GITWEB_JSLIB_FILES += static/js/lib/datetime.js
GITWEB_JSLIB_FILES += static/js/lib/cookies.js
GITWEB_JSLIB_FILES += static/js/javascript-detection.js
GITWEB_JSLIB_FILES += static/js/adjust-timezone.js
GITWEB_JSLIB_FILES += static/js/blame_incremental.js


GITWEB_REPLACE = \
-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
-e 's|++GIT_BINDIR++|$(bindir)|g' \
Expand Down Expand Up @@ -146,6 +158,11 @@ gitweb.cgi: gitweb.perl GITWEB-BUILD-OPTIONS
chmod +x $@+ && \
mv $@+ $@

static/gitweb.js: $(GITWEB_JSLIB_FILES)
$(QUIET_GEN)$(RM) $@ $@+ && \
cat $^ >$@+ && \
mv $@+ $@

### Testing rules

test:
Expand Down
76 changes: 51 additions & 25 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,18 @@ sub evaluate_uri {
'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,
Expand Down Expand Up @@ -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!;
}

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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";
}
}
Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions gitweb/static/gitweb.css
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,39 @@ div.remote {
display: inline-block;
}

/* JavaScript-based timezone manipulation */

.popup { /* timezone selection UI */
position: absolute;
/* "top: 0; right: 0;" would be better, if not for bugs in browsers */
top: 0; left: 0;
border: 1px solid;
padding: 2px;
background-color: #f0f0f0;
font-style: normal;
color: #000000;
cursor: auto;
}

.close-button { /* close timezone selection UI without selecting */
/* float doesn't work within absolutely positioned container,
* if width of container is not set explicitly */
/* float: right; */
position: absolute;
top: 0px; right: 0px;
border: 1px solid green;
margin: 1px 1px 1px 1px;
padding-bottom: 2px;
width: 12px;
height: 10px;
font-size: 9px;
font-weight: bold;
text-align: center;
background-color: #fff0f0;
cursor: pointer;
}


/* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */

/* Highlighting theme definition: */
Expand Down
20 changes: 20 additions & 0 deletions gitweb/static/js/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GIT web interface (gitweb) - JavaScript
=======================================

This directory holds JavaScript code used by gitweb (GIT web interface).
Scripts from there would be concatenated together in the order specified
by gitweb/Makefile into gitweb/static/gitweb.js, during building of
gitweb/gitweb.cgi (during gitweb building). The resulting file (or its
minification) would then be installed / deployed together with gitweb.

Scripts in 'lib/' subdirectory compose generic JavaScript library,
providing features required by gitweb but in no way limited to gitweb
only. In the future those scripts could be replaced by some JavaScript
library / framework, like e.g. jQuery, YUI, Prototype, MooTools, Dojo,
ExtJS, Script.aculo.us or SproutCore.

All scripts that manipulate gitweb output should be put outside 'lib/',
directly in this directory ('gitweb/static/js/'). Those scripts would
have to be rewritten if gitweb moves to using some JavaScript library.

See also comments in gitweb/Makefile.
Loading

0 comments on commit a6f3f17

Please sign in to comment.