]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: Make JavaScript ability to adjust timezones configurable
[Gitweb] / gitweb.perl
index ddf8ad212a98d2704ccb7858978c5217c83ebc91f7704da79c6d5fe635a011fa..8338cb9c8211551fa84674dd977abfdc9db77d43701e3839435c31e8a9833b57 100755 (executable)
@@ -492,6 +492,18 @@ our %feature = (
                'override' => 0,
                'default' => [0]},
 
                '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,
        # 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,
@@ -3887,13 +3899,19 @@ sub git_footer_html {
                      qq!           "!. href() .qq!");\n!.
                      qq!</script>\n!;
        } else {
                      qq!           "!. href() .qq!");\n!.
                      qq!</script>\n!;
        } else {
+               my ($jstimezone, $tz_cookie, $datetime_class) =
+                       gitweb_get_feature('javascript-timezone');
+
                print qq!<script type="text/javascript">\n!.
                print qq!<script type="text/javascript">\n!.
-                     qq!window.onload = function () {\n!.
-                     (gitweb_check_feature('javascript-actions') ?
-                     qq!       fixLinks();\n! : '').
-                     # last parameter to onloadTZSetup must be CSS class used by format_timestamp_html
-                     qq!       onloadTZSetup('local', 'gitweb_tz', 'datetime');\n!.
-                     qq!};\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!;
        }
 
                      qq!</script>\n!;
        }
 
@@ -4099,7 +4117,13 @@ sub git_print_section {
 
 sub format_timestamp_html {
        my $date = shift;
 
 sub format_timestamp_html {
        my $date = shift;
-       my $strtime = '<span class="datetime">'.$date->{'rfc2822'}.'</span>';
+       my $strtime = $date->{'rfc2822'};
+
+       my (undef, undef, $datetime_class) =
+               gitweb_get_feature('javascript-timezone');
+       if ($datetime_class) {
+               $strtime = qq!<span class="$datetime_class">$strtime</span>!;
+       }
 
        my $localtime_format = '(%02d:%02d %s)';
        if ($date->{'hour_local'} < 6) {
 
        my $localtime_format = '(%02d:%02d %s)';
        if ($date->{'hour_local'} < 6) {
This page took 0.147759 seconds and 4 git commands to generate.