Skip to contentSkip to conversation

gitweb: Change timezone

PATCH Superseded Jakub Narebski 2 participants 19 messages Jun 15, 2016

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover gitweb: Change timezone

This is split version (with assorted cleanups) of J.H. patch adding JavaScript-base ability to change timezone in which dates are displayed.

[PATCH 0/1] Gitweb: Change timezone
[PATCH 1/1] gitweb: javascript ability to adjust time based on timezone
Message-Id: <[email protected]>
http://thread.gmane.org/gmane.comp.version-control.git/169384/focus=169881

Below there is copy of original J.H. announcement:
JH>
JH> This is just a javascript implementation of Kevin's localtime JH> feature. It's pretty straight forward, though date handling in JH> Javascript is, special (head bangingly so).
JH>
JH> This should be good to run on any browser, with the safe fallback JH> of UTC being the default output should Javascript not work / be JH> available.

Table of contents:
~~~~~~~~~~~~~~~~~~
* [PATCH 01/11] gitweb: Split JavaScript for maintability, combining on build

Addresses issue with 'add several javascript files to be loaded'

* [PATCH 02/11] gitweb.js: Update and improve comments in JavaScript files [PATCH/RFC 03/11] gitweb.js: Provide default values for padding in padLeftStr and padLeft

Both are post-split cleanup

* [PATCH 04/11] gitweb.js: Extract and improve datetime handling [PATCH 05/11] gitweb.js: Introduce gitweb/static/js/lib/cookies.js [PATCH 06/11] gitweb.js: Provide getElementsByClassName method (if it not exists)

Creating JavaScript library

* [PATCH 07/11] gitweb: Refactor generating of long dates into format_timestamp_html [RFC/PATCH 08/11] gitweb: Unify the way long timestamp is displayed

Preparing gitweb.perl for changes

* [PATCH 09/11] gitweb: JavaScript ability to adjust time based on timezone [PATCH/RFC 10/11] gitweb.js: Add UI for selecting common timezone to display dates [PATCH/RFC 11/11] gitweb: Make JavaScript ability to adjust timezones configurable

The main part.

Shortlog:
~~~~~~~~~
Jakub Narebski (9):
gitweb: Split JavaScript for maintability, combining on build gitweb.js: Update and improve comments in JavaScript files gitweb.js: Provide default values for padding in padLeftStr and padLeft gitweb.js: Extract and improve datetime handling
gitweb.js: Introduce gitweb/static/js/lib/cookies.js gitweb.js: Provide getElementsByClassName method (if it not exists)
gitweb: Refactor generating of long dates into format_timestamp_html
gitweb: Unify the way long timestamp is displayed
gitweb: Make JavaScript ability to adjust timezones configurable

John 'Warthog9' Hawley (2):
gitweb: JavaScript ability to adjust time based on timezone gitweb.js: Add UI for selecting common timezone to display dates

Diffstat:
~~~~~~~~~

 .gitignore                                         |    1 +
 gitweb/Makefile                                    |   19 ++-
 gitweb/gitweb.perl                                 |   75 ++++--
 gitweb/static/gitweb.css                           |   25 ++
 gitweb/static/js/README                            |   20 ++
 gitweb/static/js/adjust-timezone.js                |  281 ++++++++++++++++++++
 .../static/{gitweb.js => js/blame_incremental.js}  |  228 +---------------
 gitweb/static/js/javascript-detection.js           |   43 +++
 gitweb/static/js/lib/common-lib.js                 |  224 ++++++++++++++++
 gitweb/static/js/lib/cookies.js                    |  114 ++++++++
 gitweb/static/js/lib/datetime.js                   |  176 ++++++++++++
 11 files changed, 965 insertions(+), 241 deletions(-)
 create mode 100644 gitweb/static/js/README
 create mode 100644 gitweb/static/js/adjust-timezone.js
 rename gitweb/static/{gitweb.js => js/blame_incremental.js} (74%)
 create mode 100644 gitweb/static/js/javascript-detection.js
 create mode 100644 gitweb/static/js/lib/common-lib.js
 create mode 100644 gitweb/static/js/lib/cookies.js
 create mode 100644 gitweb/static/js/lib/datetime.js

Dirstat:
~~~~~~~~
42.5% gitweb/static/js/lib/
29.5% gitweb/static/js/
18.9% gitweb/static/
8.9% gitweb/

Signature · 1 line
1.7.3
#1 lore raw

PATCH 1/11 gitweb: Split JavaScript for maintability, combining on build

Split originally single gitweb.js file into smaller files, each dealing with single issue / area of responsibility. This move should make gitweb's JavaScript code easier to maintain.

For better webapp performance it is recommended[1][2][3] to combine JavaScript files. Do it during build time (in gitweb/Makefile), by straight concatenation of files into gitweb.js file (which is now ignored as being generated). This means that there are no changes to gitweb script itself - it still uses gitweb.js or gitweb.min.js, but now generated.

[1]: http://developer.yahoo.com/performance/rules.html
"Minimize HTTP Requests" section
[2]: http://code.google.com/speed/articles/include-scripts-properly.html
"1. Combine external JavaScript files"
[3]: http://javascript-reference.info/speed-up-your-javascript-load-time.htm
"Combine Your Files" section.

See also new gitweb/static/js/README file.

---
Original J.H. patch had
JH>
JH> Enabling this will then add several javascript files to be loaded,

                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

While I agree with J.H. that for maintenance reasons JavaScript files should be split, most web best practice pages recommends to combine JavaScript files for performance. This patch allows both.

What is unfortunately not visible from diffstat below is that it is almost straightforward split of original gitweb/statis/gitweb.js file, with only some header and footer comments added.

Is there any magic git-diff / git-show onvocation that is able to turn split into patch involving solely renames / copies in split result?

 .gitignore                                         |    1 +
 gitweb/Makefile                                    |   16 ++-
 gitweb/static/js/README                            |   20 ++
 .../static/{gitweb.js => js/blame_incremental.js}  |  208 +-------------------
 gitweb/static/js/javascript-detection.js           |   43 ++++
 gitweb/static/js/lib/common-lib.js                 |  187 ++++++++++++++++++
 6 files changed, 269 insertions(+), 206 deletions(-)
 create mode 100644 gitweb/static/js/README
 rename gitweb/static/{gitweb.js => js/blame_incremental.js} (76%)
 create mode 100644 gitweb/static/js/javascript-detection.js
 create mode 100644 gitweb/static/js/lib/common-lib.js
.gitignore +1 -0
index 2cf3ca5..9e95005 100644
@@ -158,6 +158,7 @@
 /gitk-git/gitk-wish
 /gitweb/GITWEB-BUILD-OPTIONS
 /gitweb/gitweb.cgi
+/gitweb/static/gitweb.js
 /gitweb/static/gitweb.min.*
 /test-chmtime
 /test-ctype
gitweb/Makefile +15 -1
index 0a6ac00..0baa9df 100644
@@ -86,7 +86,7 @@ ifndef V
 endif
 endif
 
-all:: gitweb.cgi
+all:: gitweb.cgi static/gitweb.js
 
 GITWEB_PROGRAMS = gitweb.cgi
 
@@ -112,6 +112,15 @@ 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/javascript-detection.js
+GITWEB_JSLIB_FILES += static/js/blame_incremental.js
+
+
 GITWEB_REPLACE = \
 	-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
 	-e 's|++GIT_BINDIR++|$(bindir)|g' \
@@ -146,6 +155,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:
gitweb/static/js/README new file +20 -0
new file mode 100644
index 0000000..f8460ed
@@ -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.
gitweb/static/js/blame_incremental.js renamed from gitweb/static/gitweb.js +3 -205

233 lines not on this page · raw message

gitweb/static/js/javascript-detection.js new file +43 -0

43 lines not on this page · raw message

gitweb/static/js/lib/common-lib.js new file +187 -0

187 lines not on this page · raw message

Signature · 1 line
1.7.3
#2 lore raw

PATCH 2/11 gitweb.js: Update and improve comments in JavaScript files

In reply to Jakub Narebski

This consists of adding a few extra explanation, fixing descriptions of functions to match names of parameters in code, adding a few separators, and fixing spelling -- while at it spell 'neighbor' using American spelling (and not as 'neighbour').

This is post-split cleanup.

---
 gitweb/static/js/blame_incremental.js |   22 +++++++++++-----------
 gitweb/static/js/lib/common-lib.js    |   12 ++++++++----
 2 files changed, 19 insertions(+), 15 deletions(-)
gitweb/static/js/blame_incremental.js +11 -11
index f63f78b..676da6b 100644
@@ -7,7 +7,7 @@
  * @license GPLv2 or later
  */
 
-
+/* ============================================================ */
 /*
  * This code uses DOM methods instead of (nonstandard) innerHTML
  * to modify page.
@@ -26,7 +26,7 @@
  */
 
 
-/* ============================================================ */
+/* ............................................................ */
 /* utility/helper functions (and variables) */
 
 var xhr;        // XMLHttpRequest object
@@ -132,7 +132,7 @@ function writeTimeInterval() {
 }
 
 /**
- * show an error message alert to user within page (in prohress info area)
+ * show an error message alert to user within page (in progress info area)
  * @param {String} str: plain text error message (no HTML)
  *
  * @globals div_progress_info
@@ -182,7 +182,7 @@ function getColorNo(tr) {
 
 var colorsFreq = [0, 0, 0];
 /**
- * return one of given possible colors (curently least used one)
+ * return one of given possible colors (currently least used one)
  * example: chooseColorNoFrom(2, 3) returns 2 or 3
  *
  * @param {Number[]} arguments: one or more numbers
@@ -203,8 +203,8 @@ function chooseColorNoFrom() {
 }
 
 /**
- * given two neigbour <tr> elements, find color which would be different
- * from color of both of neighbours; used to 3-color blame table
+ * given two neighbor <tr> elements, find color which would be different
+ * from color of both of neighbors; used to 3-color blame table
  *
  * @param {HTMLElement} tr_prev
  * @param {HTMLElement} tr_next
@@ -216,14 +216,14 @@ function findColorNo(tr_prev, tr_next) {
 	var color_next = getColorNo(tr_next);
 
 
-	// neither of neighbours has color set
+	// neither of neighbors has color set
 	// THEN we can use any of 3 possible colors
 	if (!color_prev && !color_next) {
 		return chooseColorNoFrom(1,2,3);
 	}
 
-	// either both neighbours have the same color,
-	// or only one of neighbours have color set
+	// either both neighbors have the same color,
+	// or only one of neighbors have color set
 	// THEN we can use any color except given
 	var color;
 	if (color_prev === color_next) {
@@ -237,7 +237,7 @@ function findColorNo(tr_prev, tr_next) {
 		return chooseColorNoFrom((color % 3) + 1, ((color+1) % 3) + 1);
 	}
 
-	// neighbours have different colors
+	// neighbors have different colors
 	// THEN there is only one color left
 	return (3 - ((color_prev + color_next) % 3));
 }
@@ -258,7 +258,7 @@ function isStartOfGroup(tr) {
 
 /**
  * change colors to use zebra coloring (2 colors) instead of 3 colors
- * concatenate neighbour commit groups belonging to the same commit
+ * concatenate neighbor commit groups belonging to the same commit
  *
  * @globals colorRe
  */
gitweb/static/js/lib/common-lib.js +8 -4
index 38f3b9e..6a6d200 100644
@@ -13,14 +13,17 @@
 /* Padding */
 
 /**
- * pad number N with nonbreakable spaces on the left, to WIDTH characters
+ * pad INPUT on the left with STR that is assumed to have visible
+ * width of single character (for example nonbreakable spaces),
+ * to WIDTH characters
+ *
  * example: padLeftStr(12, 3, '\u00A0') == '\u00A012'
  *          ('\u00A0' is nonbreakable space)
  *
  * @param {Number|String} input: number to pad
  * @param {Number} width: visible width of output
  * @param {String} str: string to prefix to string, e.g. '\u00A0'
- * @returns {String} INPUT prefixed with (WIDTH - INPUT.length) x STR
+ * @returns {String} INPUT prefixed with STR x (WIDTH - INPUT.length)
  */
 function padLeftStr(input, width, str) {
 	var prefix = '';
@@ -34,7 +37,7 @@ function padLeftStr(input, width, str) {
 }
 
 /**
- * Pad INPUT on the left to SIZE width, using given padding character CH,
+ * Pad INPUT on the left to WIDTH, using given padding character CH,
  * for example padLeft('a', 3, '_') is '__a'.
  *
  * @param {String} input: input value converted to string.
@@ -140,7 +143,8 @@ var maybeQuotedRe = /^\"(.*)\"$/;
 /**#@-*/
 
 /**
- * unquote maybe git-quoted filename
+ * unquote maybe C-quoted filename (as used by git, i.e. it is
+ * in double quotes '"' if there is any escape character used)
  * e.g. 'aa' -> 'aa', '"a\ta"' -> 'a	a'
  *
  * @param {String} str: git-quoted string
Signature · 1 line
1.7.3
#3 lore raw

PATCH 3/11 gitweb.js: Provide default values for padding in padLeftStr and padLeft

In reply to Jakub Narebski

This means that one can use padLeft(4, 2) and it would be equivalent to runing padLeft(4, 2, '0'), and it would return '04' i.e. '4' padded with '0' to width 2, to be used e.g. in formatting date and time.

This should make those functions easier to use. Current code doesn't yet make use of this feature.

---
This patch is not strictly necessary, but it makes those functions easier to use, I guess.

Removing this patch would require some trivially resolvable changes to next commits in this series.

 gitweb/static/js/lib/common-lib.js |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
gitweb/static/js/lib/common-lib.js +11 -3
index 6a6d200..c45454e 100644
@@ -22,11 +22,14 @@
  *
  * @param {Number|String} input: number to pad
  * @param {Number} width: visible width of output
- * @param {String} str: string to prefix to string, e.g. '\u00A0'
+ * @param {String} str: string to prefix to string, defaults to '\u00A0'
  * @returns {String} INPUT prefixed with STR x (WIDTH - INPUT.length)
  */
 function padLeftStr(input, width, str) {
 	var prefix = '';
+	if (typeof str === 'undefined') {
+		ch = '\u00A0'; // using '&nbsp;' doesn't work in all browsers
+	}
 
 	width -= input.toString().length;
 	while (width > 0) {
@@ -38,16 +41,21 @@ function padLeftStr(input, width, str) {
 
 /**
  * Pad INPUT on the left to WIDTH, using given padding character CH,
- * for example padLeft('a', 3, '_') is '__a'.
+ * for example padLeft('a', 3, '_') is '__a'
+ *             padLeft(4, 2) is '04' (same as padLeft(4, 2, '0'))
  *
  * @param {String} input: input value converted to string.
  * @param {Number} width: desired length of output.
- * @param {String} ch: single character to prefix to string.
+ * @param {String} ch: single character to prefix to string, defaults to '0'.
  *
  * @returns {String} Modified string, at least SIZE length.
  */
 function padLeft(input, width, ch) {
 	var s = input + "";
+	if (typeof ch === 'undefined') {
+		ch = '0';
+	}
+
 	while (s.length < width) {
 		s = ch + s;
 	}
Signature · 1 line
1.7.3
#4 lore raw

PATCH 4/11 gitweb.js: Extract and improve datetime handling

In reply to Jakub Narebski

Move formatDateISOLocal(epoch, timezone) function (and also helper timezoneOffset(timezoneInfo) function it requires) from common-lib.js to datetime.js

Add new functions:
* localTimezoneOffset - to get browser timezone offset in seconds
* localTimezoneInfo - to get browser timezone in '(+|-)HHMM' format
* formatTimezoneInfo - turn offset in hours and minutes into '(+|-)HHMM'
* parseRFC2822Date - to parse RFC-2822 dates that gitweb uses into epoch
* formatDateRFC2882 - like formatDateISOLocal, only RFC-2822 format

All those functions are meant to be used in future commit 'gitweb: javascript ability to adjust time based on timezone'

An alternative would be to use e.g. Datejs (http://www.datejs.com)
library.

While at it escape '-' in character class inside tzRe regexp, as recommended by JSLint (http://www.jslint.com).

---
The major difference to approach taken in J.H. patch is noticing that while in older browsers Date constructor (Date.parse class method) does not like ISO-8601 format (W3CDTF variant used in microformats), all browsers should be able to parse RFC-822 / RFC-2822 date... which is what gitweb generates.

So instead of using deprecated (because of accessibility considerations) datetime-design-pattern microformat, or newer value-class-pattern (perhaps in value-title variant), simply parse RFC-2822 date that gitweb generated.

 gitweb/Makefile                    |    1 +
 gitweb/static/js/lib/common-lib.js |   51 -----------
 gitweb/static/js/lib/datetime.js   |  161 ++++++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 51 deletions(-)
 create mode 100644 gitweb/static/js/lib/datetime.js
gitweb/Makefile +1 -0
index 0baa9df..403265a 100644
@@ -117,6 +117,7 @@ GITWEB_FILES += static/git-logo.png static/git-favicon.png
 # 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/javascript-detection.js
 GITWEB_JSLIB_FILES += static/js/blame_incremental.js
 
gitweb/static/js/lib/common-lib.js +0 -51

57 lines not on this page · raw message

gitweb/static/js/lib/datetime.js new file +161 -0

161 lines not on this page · raw message

Signature · 1 line
1.7.3
#5 lore raw

PATCH 5/11 gitweb.js: Introduce gitweb/static/js/lib/cookies.js

In reply to Jakub Narebski

This file provides functions for setting, getting and deleting cookies.

Code taken from subsection "Cookies in JavaScript" of "Professional JavaScript for Web Developers" by Nicholas C. Zakas and from cookie plugin for jQuery (dual licensed under the MIT and GPL licenses).

---
Instead of setCookieExp and setCookie (with different behaviors) in J.H. patch, use single setCookie function. The code in this patch consistently assumes that the name of cookie doesn't need to be escaped, and that value of cookie needs to escaped / unescaped (using encodeURIComponent rather than deprecated escape).

Because remembering which positional parameter (beyond name and value of cookie) corresponds to which cookie attribute often requires checking the code, follow convention used in jQery cookie plugin of using object literal to implement "named parameters".

Note that J.H.'s gitweb/static/js/cookies.js had a few errors in its implementation.

P.S. The summary line (subject) for this commit could be better.

 gitweb/Makefile                 |    1 +
 gitweb/static/js/lib/cookies.js |  114 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 gitweb/static/js/lib/cookies.js
gitweb/Makefile +1 -0
index 403265a..7dd1dee 100644
@@ -118,6 +118,7 @@ GITWEB_FILES += static/git-logo.png static/git-favicon.png
 # 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/blame_incremental.js
 
gitweb/static/js/lib/cookies.js new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
1.7.3
#6 lore raw

PATCH 6/11 gitweb.js: Provide getElementsByClassName method (if it not exists)

In reply to Jakub Narebski

The code is simplified and does not support full specification of native getElementsByClassName method, but implements just subset that would be enough for gitweb, supporting only single class name.

---
Instead of providing findElementsByClassName function like in J.H. patch, which could use getElementsByClassName if present (but didn't cache check for document.getElementsByClassName), this version adds getElementsByClassName method to 'document' if it doesn't exist.

Which solution is better / easier to understand? I'm not sure.

 gitweb/static/js/lib/common-lib.js |   51 ++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
gitweb/static/js/lib/common-lib.js +51 -0
index d6b0c0d..b371391 100644
@@ -89,6 +89,57 @@ function createRequestObject() {
 
 
 /* ............................................................ */
+/* Support for legacy browsers */
+
+/**
+ * Provides getElementsByClassName method, if there is no native
+ * implementation of this method.
+ *
+ * NOTE that there are limits and differences compared to native
+ * getElementsByClassName as defined by e.g.:
+ *   https://developer.mozilla.org/en/DOM/document.getElementsByClassName
+ *   http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-getelementsbyclassname
+ *   http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-getelementsbyclassname
+ *
+ * Namely, this implementation supports only single class name as
+ * argument and not set of space-separated tokens representing classes,
+ * it returns Array of nodes rather than live NodeList, and has
+ * additional optional argument where you can limit search to given tags
+ * (via getElementsByTagName).
+ *
+ * Based on
+ *   http://code.google.com/p/getelementsbyclassname/
+ *   http://www.dustindiaz.com/getelementsbyclass/
+ *   http://stackoverflow.com/questions/1818865/do-we-have-getelementsbyclassname-in-javascript
+ *
+ * See also http://ejohn.org/blog/getelementsbyclassname-speed-comparison/
+ *
+ * @param {String} class: name of _single_ class to find
+ * @param {String} [taghint] limit search to given tags
+ * @returns {Node[]} array of matching elements
+ */
+if (!('getElementsByClassName' in document)) {
+	document.getElementsByClassName = function (classname, taghint) {
+		taghint = taghint || "*";
+		var elements = (taghint === "*" && document.all) ?
+		               document.all :
+		               document.getElementsByTagName(taghint);
+		var pattern = new RegExp("(^|\\s)" + classname + "(\\s|$)");
+		var matches= [];
+		for (var i = 0, j = 0, n = elements.length; i < n; i++) {
+			var el= elements[i];
+			if (el.className && pattern.test(el.className)) {
+				// matches.push(el);
+				matches[j] = el;
+				j++;
+			}
+		}
+		return matches;
+	};
+} // end if
+
+
+/* ............................................................ */
 /* unquoting/unescaping filenames */
 
 /**#@+
Signature · 1 line
1.7.3
#7 lore raw

PATCH 7/11 gitweb: Refactor generating of long dates into format_timestamp_html

In reply to Jakub Narebski

It is pure refactoring and doesn't change gitweb output, though this could potentially affect 'summary', 'log', and 'commit'-like views ('commit', 'commitdiff', 'tag').

Remove print_local_time and format_local_time, as their use is now replaced (indirectly) by using format_timestamp_html.

While at it improve whitespace formatting.

---
This helper subroutine would reduce a bit code repetition that can be found in original J.H. patch.

 gitweb/gitweb.perl |   45 ++++++++++++++++++++++-----------------------
 1 files changed, 22 insertions(+), 23 deletions(-)
gitweb/gitweb.perl +22 -23
index ee69ea6..7329db2 100755
@@ -3938,22 +3938,21 @@ sub git_print_section {
 	print $cgi->end_div;
 }
 
-sub print_local_time {
-	print format_local_time(@_);
-}
+sub format_timestamp_html {
+	my ($date, %opts) = @_;
+	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'});
+	return $strtime unless $opts{'-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 $localtime;
+	return $strtime;
 }
 
 # Outputs the author name and date in long form
@@ -3966,10 +3965,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, %opts)."]".
+	      git_get_avatar($co->{'author_email'}, -pad_before => 1) .
+	      "</$tag>\n";
 }
 
 # Outputs table rows containing the full author or committer information,
@@ -3986,16 +3984,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, -localtime=>1) .
+		      "</td>" .
 		      "</tr>\n";
 	}
 }
@@ -5410,7 +5408,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
Signature · 1 line
1.7.3
#8 lore raw

PATCH 8/11 gitweb: Unify the way long timestamp is displayed

In reply to Jakub Narebski

format_timestamp_html loses its "-localtime => 1" option, and now always print the local time (in author/comitter/tagger local timezone), with "atnight" warning if needed.

This means that both 'summary' and 'log' views now display localtime. In the case of 'log' view this can be thought as an improvement, as now one can easily see which commits in a series are made "atnight" and should be examined closer.

---
Not really necessary, though dropping it from series would probably require resolving trivial spurious textual conflicts.

It is marked as an RFC because I am not quite satisfied with the way 'log' view looks like after this change, though OTOH this change is an improvement for 'log' view...

 gitweb/gitweb.perl |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
gitweb/gitweb.perl +3 -5
index 7329db2..67bcfe8 100755
@@ -3939,11 +3939,9 @@ sub git_print_section {
 }
 
 sub format_timestamp_html {
-	my ($date, %opts) = @_;
+	my $date = shift;
 	my $strtime = $date->{'rfc2822'};
 
-	return $strtime unless $opts{'-localtime'};
-
 	my $localtime_format = '(%02d:%02d %s)';
 	if ($date->{'hour_local'} < 6) {
 		$localtime_format = '(<span class="atnight">%02d:%02d</span> %s)';
@@ -3965,7 +3963,7 @@ 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)) .
-	      " [".format_timestamp_html(\%ad, %opts)."]".
+	      " [".format_timestamp_html(\%ad)."]".
 	      git_get_avatar($co->{'author_email'}, -pad_before => 1) .
 	      "</$tag>\n";
 }
@@ -3992,7 +3990,7 @@ sub git_print_authorship_rows {
 		      "</td></tr>\n" .
 		      "<tr>" .
 		      "<td></td><td>" .
-		      format_timestamp_html(\%wd, -localtime=>1) .
+		      format_timestamp_html(\%wd) .
 		      "</td>" .
 		      "</tr>\n";
 	}
Signature · 1 line
1.7.3
#9 lore raw

PATCH 9/11 gitweb: JavaScript ability to adjust time based on timezone

In reply to Jakub Narebski

From: John 'Warthog9' Hawley <[email protected]>

This patch is based on Kevin Cernekee's <[email protected]> patch series entitled "gitweb: introduce localtime feature". While Kevin's patch changed the server side output so that the timezone was output from gitweb itself, this has a number of drawbacks, in particular with respect to gitweb-caching.

This patch takes the same basic goal, display the appropriate times in a given common timezone, and implements it in JavaScript. This requires adding / using a new class, "datetime", to be able to find elements to be adjusted from JavaScript. Appropriate dates are wrapped in a span with this class.

Timezone to be used can be retrieved from "gitweb_tz" cookie, though currently there is no way to set / manipulate this cookie from gitweb; this is left for later commit.

Valid timezones, currently, are: "utc", "local" (which means that timezone is taken from browser), and "+/-ZZZZ" numeric timezone as in RFC-2822. Default timezone is "local" (currently not configurable, left for later commit... though one could edit browser cookie externally).

Fallback (should JavaScript not be enabled) is to treat dates as they have been and display them, only, in UTC.

Pages affected:
* 'summary' view, "last change" field (commit time from latest change)
* 'log' view, author time
* 'commit' and 'commitdiff' views, author/committer time
* 'tag' view, tagger time

Based-on-code-from: Kevin Cernekee <[email protected]>

---
This is major part of J.H. patch.

NOTE that while major ideas (and some of names) are taken from J.H. patch, the code was practically written anew from scratch.

I avoid using global variables, as recommended in various tips for better JavaScript performance. Global variables are discouraged anyway...

Actual interface for changing / selecting timezone is left for later commit, both because smaller patches are easier to review, and because interface part is more tricky and involves more issue.

 gitweb/Makefile                     |    1 +
 gitweb/gitweb.perl                  |   11 +++++--
 gitweb/static/js/adjust-timezone.js |   59 +++++++++++++++++++++++++++++++++++
 gitweb/static/js/lib/datetime.js    |   15 +++++++++
 4 files changed, 83 insertions(+), 3 deletions(-)
 create mode 100644 gitweb/static/js/adjust-timezone.js
gitweb/Makefile +1 -0
index 7dd1dee..5d20515 100644
@@ -120,6 +120,7 @@ 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/gitweb.perl +8 -3
index 67bcfe8..6651946 100755
@@ -3732,9 +3732,14 @@ 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 {
 		print qq!<script type="text/javascript">\n!.
-		      qq!window.onload = fixLinks;\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!</script>\n!;
 	}
 
@@ -3940,7 +3945,7 @@ sub git_print_section {
 
 sub format_timestamp_html {
 	my $date = shift;
-	my $strtime = $date->{'rfc2822'};
+	my $strtime = '<span class="datetime">'.$date->{'rfc2822'}.'</span>';
 
 	my $localtime_format = '(%02d:%02d %s)';
 	if ($date->{'hour_local'} < 6) {
gitweb/static/js/adjust-timezone.js new file +59 -0

59 lines not on this page · raw message

gitweb/static/js/lib/datetime.js +15 -0
index b3dcedb..f78c60a 100644
@@ -105,6 +105,21 @@ function formatTimezoneInfo(hours, minutes, sep) {
 }
 
 /**
+ * translate 'utc' and 'local' to numerical timezone
+ * @param {String} timezoneInfo: might be 'utc' or 'local' (browser)
+ */
+function normalizeTimezoneInfo(timezoneInfo) {
+	switch (timezoneInfo) {
+	case 'utc':
+		return '+0000';
+	case 'local': // 'local' is browser timezone
+		return localTimezoneInfo();
+	}
+	return timezoneInfo;
+}
+
+
+/**
  * return date in local time formatted in iso-8601 like format
  * 'yyyy-mm-dd HH:MM:SS +/-ZZZZ' e.g. '2005-08-07 21:49:46 +0200'
  *
Signature · 1 line
1.7.3
#10 lore raw

PATCH 10/11 gitweb.js: Add UI for selecting common timezone to display dates

In reply to Jakub Narebski

From: John 'Warthog9' Hawley <[email protected]>

This will modify HTML, add CSS rules and add DOM event handlers so that clicking on any date (the common part, not the localtime part) will display a drop down menu to choose the timezone to change to.

Currently menu displays only the following timezones:

utc
local
-1200
-1100
...
+1100
+1200
+1300
+1400

In timezone selection menu each timezone is +1hr to the previous. The code is capable of handling fractional timezones, but those have not been added to the menu.

All changes are saved to a cookie, so page changes and closing / reopening browser retains the last known timezone setting used.

[jn: Changed from innerHTML to DOM, moved to event delegation for onclick to trigger menu, added close button and cookie refreshing]

KNOWN BUGS:
===========
* In 'log' view menu is generated on the right side of whole page, instead of at near date, as is the case with 'summary', 'commit', 'commitdiff', and 'tag' views.

* Replacing inline style for 'popup' and 'close-button' elements of timezone menu with style defined in gitweb.css results in menu being put between datetime and its local part, as if absolute positioning didn't remove element from the flow.

Currently style is duplicated in gitweb.css (in CSS file) and in <element>.style.cssText (in JavaScript).

* 'close-button' is not placed correctly if it uses 'float: right;' style (problem floating element in absolutely positioned box, even though there is no problem if containing box is has position: fixed).

Therefore it was necessary to use absolute positioning for close button. This might cause for it to overlay 'Select timezone:' text in some cases.

KNOWN ISSUES:
=============
* It is not easy to discover how to change timezone of dates in gitweb output... though the same can be said for other parts of gitweb output. Also marking of dates might be a bit misleading.

* Markup should probably change when timezone selection menu is displayed. Timezone UI could also be improved.

---
Changes from J.H. patch:
~~~~~~~~~~~~~~~~~~~~~~~~
* In J.H. patch to display timezone menu you had to click small "+" beside date, that was added for each date using JavaScript.

In this patch to display timezone menu you have to click anywhere on date, as hinted by title='Click to change timezone' added to those elements via JavaScript, and link-like view on :hover via CSS added with JavaScript.

* In J.H. patch clicking on "+" was handled with setting onclick for each such element:

    <span onclick="clickDate(event.target);" title="+">+</span>

once for each date (but only for 'log' view there are many dates).

In this patch clicking on dates is handled via event delegation (event capturing for 'document').

* In J.H. patch timezone menu was generated from scratch on each click on unopened "+" (which changed to "-" and handled closing) by setting target.innerHTML to string generated by concatenation.

In this patch timezone menu is generated once on page load, and only attached on clicking on date. This menu is generated using DOM methods rather than innerHTML -- this is because my ancient browser (Mozilla 1.17.12 Gecko/20050923) considers innerHTML non-standard with strict mode (XHTML + application/xhtml+xml).

* In J.H. patch to remove timezone menu without selection you had to click on "-" (turning it again into "+").

In this patch to remove timezone menu you had to click '[x]' button marked with title='(click on this box to close)'.

* In J.H. patch timezone menu was composed of table. In this patch it is simply <div> element.

* In J.H. patch to get date gitweb JavaScript parsed title attribute. In this patch to get date gitweb JavaScript parses contents of element.

On one hand side with current code is hopefully easier to understand code flow. On the other hand it uses much more advanced features of
JavaScript: DOM (mainly DOM HTML, with bits of CSS, Style and Core), event delegation, closures, absolute positioning / visual model.

 gitweb/static/gitweb.css            |   25 ++++
 gitweb/static/js/adjust-timezone.js |  242 +++++++++++++++++++++++++++++++++--
 gitweb/static/js/lib/common-lib.js  |   27 ++++-
 3 files changed, 283 insertions(+), 11 deletions(-)
gitweb/static/gitweb.css +25 -0
index 79d7eeb..6d17e12 100644
@@ -579,6 +579,31 @@ div.remote {
 	display: inline-block;
 }
 
+/* JavaScript-base timezone manipulation */
+
+.popup { // timezone selection UI
+	position: absolute;
+	top: 0; right: 0;
+	border: 1px solid;
+	background-color: #f0f0f0;
+}
+
+.close-button { // close timezone selection UI without selecting
+	//float: right; // float doesn't work within absolutely positioned container
+	position: absolute;
+	top: 0px; right: 0px;
+	border:  1px solid green;
+	margin:  1px 1px 1px 1px;
+	padding: 1px 1px 1px 1px;
+	width:     10px;
+	height:    10px;
+	font-size:  8px;
+	font-weight: bold;
+	text-align: center;
+	background-color: #fff0f0;
+}
+
+
 /* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */
 
 /* Highlighting theme definition: */
gitweb/static/js/adjust-timezone.js +232 -10

270 lines not on this page · raw message

gitweb/static/js/lib/common-lib.js +26 -1
index b371391..faff9b6 100644
@@ -64,7 +64,7 @@ function padLeft(input, width, ch) {
 
 
 /* ............................................................ */
-/* Ajax */
+/* Handling browser incompatibilities */
 
 /**
  * Create XMLHttpRequest object in cross-browser way
@@ -88,6 +88,31 @@ function createRequestObject() {
 }
 
 
+/**
+ * Insert rule giving specified STYLE to given SELECTOR at the end of
+ * first CSS stylesheet.
+ *
+ * @param {String} selector: CSS selector, e.g. '.class'
+ * @param {String} style: rule contents, e.g. 'background-color: red;'
+ */
+function addCssRule(selector, style) {
+	var stylesheet = document.styleSheets[0];
+
+	var theRules = [];
+	if (stylesheet.cssRules) {     // W3C way
+		theRules = stylesheet.cssRules;
+	} else if (stylesheet.rules) { // IE way
+		theRules = stylesheet.rules;
+	}
+
+	if (stylesheet.insertRule) {    // W3C way
+		stylesheet.insertRule(selector + ' { ' + style + ' }', theRules.length);
+	} else if (stylesheet.addRule) { // IE way
+		stylesheets.addRule(selector, style);
+	}
+}
+
+
 /* ............................................................ */
 /* Support for legacy browsers */
 
Signature · 1 line
1.7.3
#14 lore raw

PATCH 11/11 gitweb: Make JavaScript ability to adjust timezones configurable

In reply to Jakub Narebski

Configure JavaScript-based ability to select common timezone for git dates via %feature mechanism, namely 'javascript-timezone' feature.

The following settings are configurable:
* default timezone (defaults to 'local' i.e. browser timezone); this also can function as a way to disable this ability, by setting it to false-ish value (undef or '')
* name of cookie to store user's choice of timezone
* class name to mark dates

NOTE: This is a bit of abuse of %feature system, which can store only sequence of values, rather than dictionary (hash); usually but not always only a single value is used.

---
Original patch by J.H. had strictly speaking only $jslocaltime (default timezone) configurable, though cookie name was stored in global variable (set in gitweb/static/js/common-defs.js).

But do we really need full flexibility...?

 gitweb/gitweb.perl |   37 ++++++++++++++++++++++++++++++-------
 1 files changed, 30 insertions(+), 7 deletions(-)
gitweb/gitweb.perl +30 -7
index 6651946..b80f2e0 100755
@@ -480,6 +480,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,
@@ -3733,13 +3745,18 @@ sub git_footer_html {
 		      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!.
-		      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!	onloadTZSetup('$jstimezone', '$tz_cookie', '$datetime_class');\n!;
+		}
+		print qq!};\n!.
 		      qq!</script>\n!;
 	}
 
@@ -3945,7 +3962,13 @@ sub git_print_section {
 
 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">$strtime</span>!;
+	}
 
 	my $localtime_format = '(%02d:%02d %s)';
 	if ($date->{'hour_local'} < 6) {
Signature · 1 line
1.7.3
#11 lore raw

Re: [PATCH/RFC 10/11] gitweb.js: Add UI for selecting common timezone to display dates

In reply to Jakub Narebski
Quoted 5 lines · Jakub Narebski

KNOWN BUGS:
===========
* In 'log' view menu is generated on the right side of whole page, instead of at near date, as is the case with 'summary', 'commit', 'commitdiff', and 'tag' views.

I'm not sure if it is behavior expected by CSS visual formatting model or not: the issue is with absolutely positioned block element

div.popup { position: absolute; top: 0; right: 0; }

inside relatively positioned _inline_ element

span.marker { position: relative; }

In this case 'top: 0; right: 0' refers somehow to parent block element of inline element... at least that's what I think. Note that also in the case of 'summary', 'commit', 'commitdiff' and 'tag' views the popup position is not entirely what one could expect...

What is strange is that 'top: 0; left: 0' works correctly (sic!).

Quoted 8 lines

* 'close-button' is not placed correctly if it uses 'float: right;' style (problem floating element in absolutely positioned box, even though there is no problem if containing box is has
position: fixed).

Therefore it was necessary to use absolute positioning for close button. This might cause for it to overlay 'Select timezone:' text in some cases.

This is because browser didn't determine width of '.popup' block element at the time when float element is positioned. Setting explicitly width of timezone menu will allow to use float for '.close-button'.

Both normally positioned and fixed positioned block elements have by default 100% width, that is why it worked for them.

Can fix in next iteration.

Signature · 2 lines
Jakub Narebski
Poland
#12 lore raw

Re: [PATCH/RFC 10/11] gitweb.js: Add UI for selecting common timezone to display dates

Quoted 15 lines · Jakub Narebski
Quoted 5 lines · Jakub Narebski

KNOWN BUGS:
===========
* In 'log' view menu is generated on the right side of whole page, instead of at near date, as is the case with 'summary', 'commit', 'commitdiff', and 'tag' views.

I'm not sure if it is behavior expected by CSS visual formatting model or not: the issue is with absolutely positioned block element

  div.popup { position: absolute; top: 0; right: 0; }

inside relatively positioned _inline_ element

Quoted 8 lines

  span.marker { position: relative; }

In this case 'top: 0; right: 0' refers somehow to parent block element of inline element... at least that's what I think.  Note that also in the case of 'summary', 'commit', 'commitdiff' and 'tag' views the popup position is not entirely what one could expect...

What is strange is that 'top: 0; left: 0' works correctly (sic!).

This looks like a bug in Mozilla 1.7.12 (Gecko/20050923) I ordinarily use. Checking simplified test case with Konqueror 3.5.3 shows correct behavior for all combinations of absolute positioning, at least when

    span.marker { position: relative; display: inline-block; }

Without "display: inline-block;" the "top: 0; right: 0;" is displaced compared to the end of marker.

Because vger anti-spam filter doesn't like HTML attachments, you can check test case here: https://gist.github.com/912389

Try it also with 'display: inline-block;' uncommented.

Signature · 2 lines
Jakub Narebski
Poland
#13 lore raw

Re: [PATCH/RFC 10/11] gitweb.js: Add UI for selecting common timezone to display dates

In reply to Jakub Narebski
Quoted 10 lines · Jakub Narebski

KNOWN BUGS:
===========

* Replacing inline style for 'popup' and 'close-button' elements of timezone menu with style defined in gitweb.css results in menu being put between datetime and its local part, as if absolute positioning didn't remove element from the flow.

Currently style is duplicated in gitweb.css (in CSS file) and in <element>.style.cssText (in JavaScript).

I'm very sorry, false alarm. The error was mine: the CSS in gitweb.css is incorrect; I forgot that in CSS you have only C-like "/* foo */" comments, and C++ / JavaScript-like "// ... \n" doesn't work.

See e.g.: http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Frepo.or.cz%2Fw%2Fgit%2Fjnareb-git.git%2Fblob_plain%2F524656258696381f9e6b9169256688165e21a3f9%3A%2Fgitweb%2Fstatic%2Fgitweb.css&lang=en&profile=css21&usermedium=all&warning=1

Will fix.

gitweb/static/gitweb.css div.remote { · line 584

Quoted 11 lines
gitweb/static/gitweb.css +3 -0
index 79d7eeb..6d17e12 100644
@@ -579,6 +579,31 @@ div.remote {
 	display: inline-block;
 }
 
+/* JavaScript-base timezone manipulation */
+
+.popup { // timezone selection UI
            ^^

Should be

+.popup { /* timezone selection UI */

Quoted 5 lines
gitweb/static/gitweb.css +5 -0
+	position: absolute;
+	top: 0; right: 0;
+	border: 1px solid;
+	background-color: #f0f0f0;
+}
Signature · 2 lines
Jakub Narebski
Poland
#15 lore raw
In reply to Jakub Narebski
Quoted 3 lines · Jakub Narebski

This is split version (with assorted cleanups) of J.H. patch adding JavaScript-base ability to change timezone in which dates are displayed.

Jakub,

Thanks for the update. This UI does seem to work better than the original "[+]" dropdown interface.

The new code appears to degrade gracefully on IE6 (everything shown in UTC).

Tests on Firefox 3.6.15 looked OK.

Chromium 6.0.472.62 (59676) does not like this operation:

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
removeChangeTZForm
/gitweb-static/gitweb.js:785
onTZFormChange

line 785: var removed = container.removeChild(container.lastChild);

Opera 10.63 resets target.selectedIndex to 1 after calling removeChangeTZForm() from onTZFormChange(). Net effect is that you're always stuck in the "local" zone. Here is a workaround that fixed it for me:

       var target = event.target || event.srcElement;
       var selectedIndex = target.selectedIndex;

       removeChangeTZForm(documentFragment, target, tzClassName);

       var selected = target.options.item(selectedIndex);

Couple other random nitpicks:

Review

Quoted 3 lines
(quoted diff) +3 -0
+	// server-side of gitweb produces datetime in UTC,
+	// so if tz is 'utc' there is no need for changes
+	var nochange = tz === 'utc';

If I delete my gitweb_tz cookie, then refresh the page:

- All times show up in my browser's local time (good)

- Clicking UTC/GMT on the dropdown has no immediate effect; I need to refresh the page again to see the times change (bad)

Review

Quoted 4 lines
(quoted diff) +4 -0
+	my (undef, undef, $datetime_class) =
+		gitweb_get_feature('javascript-timezone');
+	if ($datetime_class) {
+		$strtime = qq!<span class="datetime">$strtime</span>!;

Should this hard-code class "datetime", or use $datetime_class from the gitweb server configuration?

Quoted 1 line

+/* JavaScript-base timezone manipulation */

Might want to reword as "JavaScript-based"

Review

Quoted 2 lines
(quoted diff) +2 -0
+		// refresh cookie, so it expires 7 days from last use of gitweb
+		setCookie(tzCookieName, tzCookie, { expires: 7, path: '/' });

Hmm, only 7 days?

Quoted 1 line

+ * and instals appropriate onclick trigger (via event delegation).

"installs"

#16 lore raw
Quoted 10 lines · Kevin Cernekee
Quoted 4 lines · Jakub Narebski

This is split version (with assorted cleanups) of J.H. patch adding JavaScript-base ability to change timezone in which dates are displayed.

Jakub,

Thanks for the update. This UI does seem to work better than the original "[+]" dropdown interface.

Thanks.

Notice that you can have only one timezone selection menu opened. You have to close existing to be able to open it in different place (near different date), even though onclick handler still triggers.

This is caused by the fact that appending DocumentFragment to an element "empties" it, as described in DOM 2 Core specification[1]:

appendChild
Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.

Parameters

newChild of type Node
The node to add.

If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[1]: http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-184E7107

That is also the case that we need to read it when closing timezone selection menu in removeChangeTZForm():

	// timezone selection UI was appended as last child
	// see also displayChangeTZForm function
	var removed = container.removeChild(popup);
	if (documentFragment.firstChild !== removed) { // the only child
		// re-append it so it would be available for next time
		documentFragment.appendChild(removed);
	}

Though it wasn't what I thought it is needed for when writing i ;-)

You wrote in your response to original J.H. patch

"Re: [PATCH 1/1] gitweb: javascript ability to adjust time based on timezone"
http://thread.gmane.org/gmane.comp.version-control.git/169384/focus=169891

KC> I'm wondering if there might be a better place on the page to put the KC> TZ selection.  It isn't immediately obvious to the user what the KC> extra " + " does, and it seems to cause some issues.

Well, I am not sure if it is immediately obvious to user that he/she can click on date to change its timezone.

Underlining on hover (like for links... though I guess that we really should make style similar to links but not the same: it is not true link), changing cursor and title attribute hopefully help here.

Ideas on having it better discoverable certainly welcome.

KC> If you decide to keep it where it is, you might want to consider KC> absolute or fixed positioning so that other elements do not wrap KC> around it.  IOW it would work more like the dropdown menus on many KC> sites.

In this version it is done using absolute positioning, though there are few quirks and things to know about:

* To be able to position timezone menu relative to some element using absolute positioning you need to make said element relatively positioned.

   	target.style.position = 'relative';

We might have used CSS instead...

* Floating inside block element works if it has some specified size. Normal, relative and fixed positioned elements have size given by its parent element. For absolutely positioned block element you have to specify width explicitly, and not have it fit to width.

That is why close-button uses absolute positioning rather than being a float.

* The only absolute position relative to parent inline-block relative positioned element is top left. All others doesn't work correctly e.g. in my ancient Mozilla 1.17.2 -- in 'log' view timezone menu got created on the right and outside viewport (page).

That is why current solution is to use "top: 0; left: 0;".

KC> The timezone fixup javascript seemed to work reasonably well, except KC> for the hiccup with IE6.  Maybe it would be worth splitting this into KC> two patches: one to rewrite the timestamps, and a second one to add KC> the TZ selection interface.

Well, I have split in more than 2 patches, but rewriting timezone of timestamps is separate from TZ selection interface.

Quoted 1 line

The new code appears to degrade gracefully on IE6 (everything shown in UTC).

I don't know about IE6, but there was bug in IE-specific code in addCssRule (was 'stylesheets' when variable is named 'stylesheet'). Thanks for noticing this; fixed in new iteration.

Now at least in IE8 (Internet Explorer 8.0.6001.18702) it works as expected.

Quoted 1 line

Tests on Firefox 3.6.15 looked OK.

Tests in the following browsers looked OK:
* Firefox 1.7.12 (Gecko/20050123)
* Epiphany 1.6.5 (Gecko/20050123)
* Firefox 4.0 - note: not as extensively tested
* Firefox 3.6.16 (Gecko/20110319)
* Internet Explorer 8.0 (8.0.6001.18702)

Tests in Konqueror 3.5.3 (KHTML) shown something strange: it has no problems with named function expressions here

	document.onclick = function onclickHandler(event) {

but was showing syntax error in similar

	return function closeTZForm(event) {

that I used in new version of 10/11 patch. As we don't redeploy handler, we don't need function name, so in current version we use

	return function (event) {

Also after displaying timezone selection menu, and either selecting timezone or canceling selection, so that timezone UI vanishes, the date that was clicked ends up displaced a bit - moved slightly up. This doesn't affect layout too badly, and is probably bug in this version of Konqueror.

Tests in the following browsers gracefully degrade to UTC:
* Lynx 2.8.5rel.1
* ELinks 0.10.3
* w3m 0.5.1+cvs-1.946

Quoted 9 lines

Chromium 6.0.472.62 (59676) does not like this operation:

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
removeChangeTZForm
/gitweb-static/gitweb.js:785
onTZFormChange

line 785: var removed = container.removeChild(container.lastChild);

Strange. I confirm the same behavior in Google Chrome 10.0.648.204, even after changes that I though should eliminate this exception.

Note that this bug/exception doesn't cause timezones to be not translated, it only makes timezone selection menu not working.

removeChild() is DOM 2 Core method, container.lastChild' exists and is child of container' element. IE8, Firefox 3.6 and 4.0, Opera 10.63 all work, it's only Chrome / Chromium that has problems...

Quoted 11 lines

Opera 10.63 resets target.selectedIndex to 1 after calling removeChangeTZForm() from onTZFormChange(). Net effect is that you're always stuck in the "local" zone. Here is a workaround that fixed it for me:

       var target = event.target || event.srcElement;
       var selectedIndex = target.selectedIndex;

       removeChangeTZForm(documentFragment, target, tzClassName);

       var selected = target.options.item(selectedIndex);

Or just change order of those statements:

	 event = event || window.event;
	 var target = event.target || event.srcElement;

	 var selected = target.options.item(target.selectedIndex);
	 removeChangeTZForm(tzSelectFragment, target, tzClassName);

Could you check that this version works correctly in Opera 10? Thanks in advance.

Quoted 9 lines

Couple other random nitpicks:

Review

Quoted 3 lines
(quoted diff) +3 -0
+	// server-side of gitweb produces datetime in UTC,
+	// so if tz is 'utc' there is no need for changes
+	var nochange = tz === 'utc';

If I delete my gitweb_tz cookie, then refresh the page:

Quoted 4 lines

- All times show up in my browser's local time (good)

- Clicking UTC/GMT on the dropdown has no immediate effect; I need to refresh the page again to see the times change (bad)

I'm sorry, it looks like I tried to be too clever.

We should either do this _only_ in onloadTZSetup and not in fixDatetimeTZ, or abandon this micro-optimization entirely - we have to enumerate all elements with "datetime" class to add 'title' attribute anyway.

The first solution was chosen in next version of this patch.

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	my (undef, undef, $datetime_class) =
+		gitweb_get_feature('javascript-timezone');
+	if ($datetime_class) {
+		$strtime = qq!<span class="datetime">$strtime</span>!;

Should this hard-code class "datetime", or use $datetime_class from the gitweb server configuration?

Sorry, my mistake. Fixed.

Quoted 3 lines
Quoted 1 line

+/* JavaScript-base timezone manipulation */

Might want to reword as "JavaScript-based"

Done.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		// refresh cookie, so it expires 7 days from last use of gitweb
+		setCookie(tzCookieName, tzCookie, { expires: 7, path: '/' });

Hmm, only 7 days?

Well, in new version where expire time is set in one place (was one to set cookie after timezone selection, one to refresh cookie), and is increased to 14 days (2 week). Please also remember that it is time from last visit to gitweb, not last timezone change.

Quoted 3 lines
Quoted 1 line

+ * and instals appropriate onclick trigger (via event delegation).

"installs"

Done.

Thanks again for reviewing it.

Signature · 2 lines
Jakub Narebski
Poland
#17 lore raw

PATCH v2 10/11 gitweb.js: Add UI for selecting common timezone to display dates

From: John 'Warthog9' Hawley <[email protected]>

This will modify HTML, add CSS rules and add DOM event handlers so that clicking on any date (the common part, not the localtime part) will display a drop down menu to choose the timezone to change to.

Currently menu displays only the following timezones:

utc
local
-1200
-1100
...
+1100
+1200
+1300
+1400

In timezone selection menu each timezone is +1hr to the previous. The code is capable of handling fractional timezones, but those have not been added to the menu.

All changes are saved to a cookie, so page changes and closing / reopening browser retains the last known timezone setting used.

[jn: Changed from innerHTML to DOM, moved to event delegation for onclick to trigger menu, added close button and cookie refreshing]

---

Differences from v1:
* Fixed bug in gitweb.css (only /* ... */ are comments).
* fixDatetimeTZ didn't update timezone correctly if cookie was deleted and 'utc' timezone selected from menu
* Fix addCssRule for IE (typofix)
* Change code so that the fact that Opera 10.63 resets target.selectedIndex to 1 after calling removeChangeTZForm() doesn't affect timezone selection result.

* Pass all cookie parameters from gitweb.perl
* Increase cookie expiration time from 7 to 14 days
* Extract/refactor generateTZOptions function
(this makes createChangeTZForm code shorter)
* select.onchange, select.onblur, close-button.onclick handlers are now generated (this makes createChangeTZForm code shorter)
* removeChangeTZForm is more robust wrt future changes
* moved from top+right to top+left positioning, because it works correctly in wider range of [buggy] web browsers

 gitweb/gitweb.perl                  |    3 +-
 gitweb/static/gitweb.css            |   33 ++++
 gitweb/static/js/adjust-timezone.js |  294 +++++++++++++++++++++++++++++++++--
 gitweb/static/js/lib/common-lib.js  |   27 +++-
 4 files changed, 342 insertions(+), 15 deletions(-)
gitweb/gitweb.perl +2 -1
index 6651946..b1e80ef 100755
@@ -3738,7 +3738,8 @@ sub git_footer_html {
 		      (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!	var tz_cookie = { name: 'gitweb_tz', expires: 14, path: '/' };\n!. # in days
+		      qq!	onloadTZSetup('local', tz_cookie, 'datetime');\n!.
 		      qq!};\n!.
 		      qq!</script>\n!;
 	}
gitweb/static/gitweb.css +33 -0
index 79d7eeb..8dd0935 100644
@@ -579,6 +579,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: */
gitweb/static/js/adjust-timezone.js +281 -13

327 lines not on this page · raw message

gitweb/static/js/lib/common-lib.js +26 -1
index b371391..018bbb7 100644
@@ -64,7 +64,7 @@ function padLeft(input, width, ch) {
 
 
 /* ............................................................ */
-/* Ajax */
+/* Handling browser incompatibilities */
 
 /**
  * Create XMLHttpRequest object in cross-browser way
@@ -88,6 +88,31 @@ function createRequestObject() {
 }
 
 
+/**
+ * Insert rule giving specified STYLE to given SELECTOR at the end of
+ * first CSS stylesheet.
+ *
+ * @param {String} selector: CSS selector, e.g. '.class'
+ * @param {String} style: rule contents, e.g. 'background-color: red;'
+ */
+function addCssRule(selector, style) {
+	var stylesheet = document.styleSheets[0];
+
+	var theRules = [];
+	if (stylesheet.cssRules) {     // W3C way
+		theRules = stylesheet.cssRules;
+	} else if (stylesheet.rules) { // IE way
+		theRules = stylesheet.rules;
+	}
+
+	if (stylesheet.insertRule) {    // W3C way
+		stylesheet.insertRule(selector + ' { ' + style + ' }', theRules.length);
+	} else if (stylesheet.addRule) { // IE way
+		stylesheet.addRule(selector, style);
+	}
+}
+
+
 /* ............................................................ */
 /* Support for legacy browsers */
 
Signature · 1 line
1.7.3
#18 lore raw

PATCH v2 11/11 gitweb: Make JavaScript ability to adjust timezones configurable

In reply to Jakub Narebski

Configure JavaScript-based ability to select common timezone for git dates via %feature mechanism, namely 'javascript-timezone' feature.

The following settings are configurable:
* default timezone (defaults to 'local' i.e. browser timezone); this also can function as a way to disable this ability, by setting it to false-ish value (undef or '')
* name of cookie to store user's choice of timezone
* class name to mark dates

NOTE: This is a bit of abuse of %feature system, which can store only sequence of values, rather than dictionary (hash); usually but not always only a single value is used.

---

Changes from v1:
* Fixed bug in format_timestamp_html using "datetime" instead of $datetime_class.

 gitweb/gitweb.perl |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 deletions(-)
gitweb/gitweb.perl +31 -8
index b1e80ef..ac335b6 100755
@@ -480,6 +480,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,
@@ -3733,14 +3745,19 @@ sub git_footer_html {
 		      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!.
-		      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!	var tz_cookie = { name: 'gitweb_tz', expires: 14, path: '/' };\n!. # in days
-		      qq!	onloadTZSetup('local', tz_cookie, '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!;
 	}
 
@@ -3946,7 +3963,13 @@ sub git_print_section {
 
 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) {
Signature · 1 line
1.7.3