* [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript
@ 2011-03-25 21:46 Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 1/3] gitweb: Split JavaScript for maintability; concatenate on build Jakub Narebski
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Jakub Narebski @ 2011-03-25 21:46 UTC (permalink / raw)
To: git; +Cc: John 'Warthog9' Hawley, Kevin Cernekee, Jakub Narebski
This patch series is inspired by patch by John 'Warthog9' Hawley
[PATCH 1/1] gitweb: javascript ability to adjust time based on timezone
Message-Id: <1300925335-3212-2-git-send-email-warthog9@eaglescrag.net>
http://thread.gmane.org/gmane.comp.version-control.git/169384/focus=169882
that added a few new JavaScript files for the new feature that this
patch implemented.
This is marked as RFC mainly because other patches in series,
especially the last one fixing bug in gitweb's JavaScript code, should
be send independently on gitweb.js splitting.
Jakub Narebski (3):
gitweb: Split JavaScript for maintability; concatenate on build
gitweb: Update and improve comments in JavaScript files
gitweb: Fix parsing of negative fractional timezones in JavaScript
.gitignore | 1 +
gitweb/Makefile | 12 +-
.../static/{gitweb.js => js/blame_incremental.js} | 216 ++------------------
gitweb/static/js/common-lib.js | 191 +++++++++++++++++
gitweb/static/js/detect-javascript.js | 44 ++++
5 files changed, 261 insertions(+), 203 deletions(-)
rename gitweb/static/{gitweb.js => js/blame_incremental.js} (75%)
create mode 100644 gitweb/static/js/common-lib.js
create mode 100644 gitweb/static/js/detect-javascript.js
--
1.7.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH/RFC 1/3] gitweb: Split JavaScript for maintability; concatenate on build
2011-03-25 21:46 [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript Jakub Narebski
@ 2011-03-25 21:46 ` Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 2/3] gitweb: Update and improve comments in JavaScript files Jakub Narebski
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Jakub Narebski @ 2011-03-25 21:46 UTC (permalink / raw)
To: git; +Cc: John 'Warthog9' Hawley, Kevin Cernekee, Jakub Narebski
Split single gitweb.js file into smaller files, each dealing with
single thing. This 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.
Inspired-by-patch-by: John 'Warthog9' Hawley <warthog9@eaglescrag.net>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
.gitignore | 1 +
gitweb/Makefile | 12 +-
.../static/{gitweb.js => js/blame_incremental.js} | 196 +-------------------
gitweb/static/js/common-lib.js | 173 +++++++++++++++++
gitweb/static/js/detect-javascript.js | 44 +++++
5 files changed, 233 insertions(+), 193 deletions(-)
rename gitweb/static/{gitweb.js => js/blame_incremental.js} (77%)
create mode 100644 gitweb/static/js/common-lib.js
create mode 100644 gitweb/static/js/detect-javascript.js
diff --git a/.gitignore b/.gitignore
index c460c66..601c71a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -160,6 +160,7 @@
/gitk-git/gitk-wish
/gitweb/GITWEB-BUILD-OPTIONS
/gitweb/gitweb.cgi
+/gitweb/static/gitweb.js
/gitweb/static/gitweb.min.*
/test-chmtime
/test-ctype
diff --git a/gitweb/Makefile b/gitweb/Makefile
index 0a6ac00..230b1b9 100644
--- a/gitweb/Makefile
+++ b/gitweb/Makefile
@@ -86,7 +86,7 @@ ifndef V
endif
endif
-all:: gitweb.cgi
+all:: gitweb.cgi static/gitweb.js
GITWEB_PROGRAMS = gitweb.cgi
@@ -112,6 +112,11 @@ endif
GITWEB_FILES += static/git-logo.png static/git-favicon.png
+GITWEB_JSLIB_FILES += static/js/common-lib.js
+GITWEB_JSLIB_FILES += static/js/detect-javascript.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 +151,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:
diff --git a/gitweb/static/gitweb.js b/gitweb/static/js/blame_incremental.js
similarity index 77%
rename from gitweb/static/gitweb.js
rename to gitweb/static/js/blame_incremental.js
index 9c66928..3317390 100644
--- a/gitweb/static/gitweb.js
+++ b/gitweb/static/js/blame_incremental.js
@@ -1,44 +1,13 @@
// Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
// 2007, Petr Baudis <pasky@suse.cz>
-// 2008-2009, Jakub Narebski <jnareb@gmail.com>
+// 2008-2011, Jakub Narebski <jnareb@gmail.com>
/**
- * @fileOverview JavaScript code for gitweb (git web interface).
+ * @fileOverview JavaScript side of Ajax-y 'blame_incremental' view in gitweb
+ * requires functions in common-lib.js to be available
* @license GPLv2 or later
*/
-/* ============================================================ */
-/* functions for generic gitweb actions and views */
-
-/**
- * used to check if link has 'js' query parameter already (at end),
- * and other reasons to not add 'js=1' param at the end of link
- * @constant
- */
-var jsExceptionsRe = /[;?]js=[01]$/;
-
-/**
- * Add '?js=1' or ';js=1' to the end of every link in the document
- * that doesn't have 'js' query parameter set already.
- *
- * Links with 'js=1' lead to JavaScript version of given action, if it
- * exists (currently there is only 'blame_incremental' for 'blame')
- *
- * @globals jsExceptionsRe
- */
-function fixLinks() {
- var allLinks = document.getElementsByTagName("a") || document.links;
- for (var i = 0, len = allLinks.length; i < len; i++) {
- var link = allLinks[i];
- if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/;
- link.href +=
- (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
- }
- }
-}
-
-
-/* ============================================================ */
/*
* This code uses DOM methods instead of (nonstandard) innerHTML
@@ -59,71 +28,6 @@ function fixLinks() {
/* ============================================================ */
-/* generic utility functions */
-
-
-/**
- * pad number N with nonbreakable spaces on the left, 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
- */
-function padLeftStr(input, width, str) {
- var prefix = '';
-
- width -= input.toString().length;
- while (width > 0) {
- prefix += str;
- width--;
- }
- return prefix + input;
-}
-
-/**
- * Pad INPUT on the left to SIZE width, using given padding character CH,
- * for example padLeft('a', 3, '_') is '__a'.
- *
- * @param {String} input: input value converted to string.
- * @param {Number} width: desired length of output.
- * @param {String} ch: single character to prefix to string.
- *
- * @returns {String} Modified string, at least SIZE length.
- */
-function padLeft(input, width, ch) {
- var s = input + "";
- while (s.length < width) {
- s = ch + s;
- }
- return s;
-}
-
-/**
- * Create XMLHttpRequest object in cross-browser way
- * @returns XMLHttpRequest object, or null
- */
-function createRequestObject() {
- try {
- return new XMLHttpRequest();
- } catch (e) {}
- try {
- return window.createRequest();
- } catch (e) {}
- try {
- return new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {}
- try {
- return new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e) {}
-
- return null;
-}
-
-
-/* ============================================================ */
/* utility/helper functions (and variables) */
var xhr; // XMLHttpRequest object
@@ -392,98 +296,6 @@ function fixColorsAndGroups() {
}
}
-/* ............................................................ */
-/* time and data */
-
-/**
- * used to extract hours and minutes from timezone info, e.g '-0900'
- * @constant
- */
-var tzRe = /^([+-][0-9][0-9])([0-9][0-9])$/;
-
-/**
- * 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'
- *
- * @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC'
- * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
- * @returns {String} date in local time in iso-8601 like format
- *
- * @globals tzRe
- */
-function formatDateISOLocal(epoch, timezoneInfo) {
- var match = tzRe.exec(timezoneInfo);
- // date corrected by timezone
- var localDate = new Date(1000 * (epoch +
- (parseInt(match[1],10)*3600 + parseInt(match[2],10)*60)));
- var localDateStr = // e.g. '2005-08-07'
- localDate.getUTCFullYear() + '-' +
- padLeft(localDate.getUTCMonth()+1, 2, '0') + '-' +
- padLeft(localDate.getUTCDate(), 2, '0');
- var localTimeStr = // e.g. '21:49:46'
- padLeft(localDate.getUTCHours(), 2, '0') + ':' +
- padLeft(localDate.getUTCMinutes(), 2, '0') + ':' +
- padLeft(localDate.getUTCSeconds(), 2, '0');
-
- return localDateStr + ' ' + localTimeStr + ' ' + timezoneInfo;
-}
-
-/* ............................................................ */
-/* unquoting/unescaping filenames */
-
-/**#@+
- * @constant
- */
-var escCodeRe = /\\([^0-7]|[0-7]{1,3})/g;
-var octEscRe = /^[0-7]{1,3}$/;
-var maybeQuotedRe = /^\"(.*)\"$/;
-/**#@-*/
-
-/**
- * unquote maybe git-quoted filename
- * e.g. 'aa' -> 'aa', '"a\ta"' -> 'a a'
- *
- * @param {String} str: git-quoted string
- * @returns {String} Unquoted and unescaped string
- *
- * @globals escCodeRe, octEscRe, maybeQuotedRe
- */
-function unquote(str) {
- function unq(seq) {
- var es = {
- // character escape codes, aka escape sequences (from C)
- // replacements are to some extent JavaScript specific
- t: "\t", // tab (HT, TAB)
- n: "\n", // newline (NL)
- r: "\r", // return (CR)
- f: "\f", // form feed (FF)
- b: "\b", // backspace (BS)
- a: "\x07", // alarm (bell) (BEL)
- e: "\x1B", // escape (ESC)
- v: "\v" // vertical tab (VT)
- };
-
- if (seq.search(octEscRe) !== -1) {
- // octal char sequence
- return String.fromCharCode(parseInt(seq, 8));
- } else if (seq in es) {
- // C escape sequence, aka character escape code
- return es[seq];
- }
- // quoted ordinary character
- return seq;
- }
-
- var match = str.match(maybeQuotedRe);
- if (match) {
- str = match[1];
- // perhaps str = eval('"'+str+'"'); would be enough?
- str = str.replace(escCodeRe,
- function (substr, p1, offset, s) { return unq(p1); });
- }
- return str;
-}
-
/* ============================================================ */
/* main part: parsing response */
@@ -872,4 +684,4 @@ function startBlame(blamedataUrl, bUrl) {
pollTimer = setInterval(xhr.onreadystatechange, 1000);
}
-// end of gitweb.js
+/* end of blame_incremental.js */
diff --git a/gitweb/static/js/common-lib.js b/gitweb/static/js/common-lib.js
new file mode 100644
index 0000000..566c98a
--- /dev/null
+++ b/gitweb/static/js/common-lib.js
@@ -0,0 +1,173 @@
+// Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
+// 2007, Petr Baudis <pasky@suse.cz>
+// 2008-2011, Jakub Narebski <jnareb@gmail.com>
+
+/**
+ * @fileOverview Generic JavaScript code (helper functions).
+ * @license GPLv2 or later
+ */
+
+
+/* ============================================================ */
+/* ............................................................ */
+/* Padding */
+
+/**
+ * pad number N with nonbreakable spaces on the left, 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
+ */
+function padLeftStr(input, width, str) {
+ var prefix = '';
+
+ width -= input.toString().length;
+ while (width > 0) {
+ prefix += str;
+ width--;
+ }
+ return prefix + input;
+}
+
+/**
+ * Pad INPUT on the left to SIZE width, using given padding character CH,
+ * for example padLeft('a', 3, '_') is '__a'.
+ *
+ * @param {String} input: input value converted to string.
+ * @param {Number} width: desired length of output.
+ * @param {String} ch: single character to prefix to string.
+ *
+ * @returns {String} Modified string, at least SIZE length.
+ */
+function padLeft(input, width, ch) {
+ var s = input + "";
+ while (s.length < width) {
+ s = ch + s;
+ }
+ return s;
+}
+
+
+/* ............................................................ */
+/* Ajax */
+
+/**
+ * Create XMLHttpRequest object in cross-browser way
+ * @returns XMLHttpRequest object, or null
+ */
+function createRequestObject() {
+ try {
+ return new XMLHttpRequest();
+ } catch (e) {}
+ try {
+ return window.createRequest();
+ } catch (e) {}
+ try {
+ return new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {}
+ try {
+ return new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e) {}
+
+ return null;
+}
+
+
+/* ............................................................ */
+/* time and data */
+
+/**
+ * used to extract hours and minutes from timezone info, e.g '-0900'
+ * @constant
+ */
+var tzRe = /^([+-][0-9][0-9])([0-9][0-9])$/;
+
+/**
+ * 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'
+ *
+ * @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC'
+ * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
+ * @returns {String} date in local time in iso-8601 like format
+ *
+ * @globals tzRe
+ */
+function formatDateISOLocal(epoch, timezoneInfo) {
+ var match = tzRe.exec(timezoneInfo);
+ // date corrected by timezone
+ var localDate = new Date(1000 * (epoch +
+ (parseInt(match[1],10)*3600 + parseInt(match[2],10)*60)));
+ var localDateStr = // e.g. '2005-08-07'
+ localDate.getUTCFullYear() + '-' +
+ padLeft(localDate.getUTCMonth()+1, 2, '0') + '-' +
+ padLeft(localDate.getUTCDate(), 2, '0');
+ var localTimeStr = // e.g. '21:49:46'
+ padLeft(localDate.getUTCHours(), 2, '0') + ':' +
+ padLeft(localDate.getUTCMinutes(), 2, '0') + ':' +
+ padLeft(localDate.getUTCSeconds(), 2, '0');
+
+ return localDateStr + ' ' + localTimeStr + ' ' + timezoneInfo;
+}
+
+
+/* ............................................................ */
+/* unquoting/unescaping filenames */
+
+/**#@+
+ * @constant
+ */
+var escCodeRe = /\\([^0-7]|[0-7]{1,3})/g;
+var octEscRe = /^[0-7]{1,3}$/;
+var maybeQuotedRe = /^\"(.*)\"$/;
+/**#@-*/
+
+/**
+ * unquote maybe git-quoted filename
+ * e.g. 'aa' -> 'aa', '"a\ta"' -> 'a a'
+ *
+ * @param {String} str: git-quoted string
+ * @returns {String} Unquoted and unescaped string
+ *
+ * @globals escCodeRe, octEscRe, maybeQuotedRe
+ */
+function unquote(str) {
+ function unq(seq) {
+ var es = {
+ // character escape codes, aka escape sequences (from C)
+ // replacements are to some extent JavaScript specific
+ t: "\t", // tab (HT, TAB)
+ n: "\n", // newline (NL)
+ r: "\r", // return (CR)
+ f: "\f", // form feed (FF)
+ b: "\b", // backspace (BS)
+ a: "\x07", // alarm (bell) (BEL)
+ e: "\x1B", // escape (ESC)
+ v: "\v" // vertical tab (VT)
+ };
+
+ if (seq.search(octEscRe) !== -1) {
+ // octal char sequence
+ return String.fromCharCode(parseInt(seq, 8));
+ } else if (seq in es) {
+ // C escape sequence, aka character escape code
+ return es[seq];
+ }
+ // quoted ordinary character
+ return seq;
+ }
+
+ var match = str.match(maybeQuotedRe);
+ if (match) {
+ str = match[1];
+ // perhaps str = eval('"'+str+'"'); would be enough?
+ str = str.replace(escCodeRe,
+ function (substr, p1, offset, s) { return unq(p1); });
+ }
+ return str;
+}
+
+/* end of common-lib.js */
diff --git a/gitweb/static/js/detect-javascript.js b/gitweb/static/js/detect-javascript.js
new file mode 100644
index 0000000..12a221d
--- /dev/null
+++ b/gitweb/static/js/detect-javascript.js
@@ -0,0 +1,44 @@
+// Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
+// 2007, Petr Baudis <pasky@suse.cz>
+// 2008-2011, Jakub Narebski <jnareb@gmail.com>
+
+/**
+ * @fileOverview Detect if JavaScript is enabled, and pass it to server-side,
+ * so that JavaScript-only version of page would/could be used
+ * @license GPLv2 or later
+ */
+
+
+/* ============================================================ */
+/* Manipulating links */
+
+/**
+ * used to check if link has 'js' query parameter already (at end),
+ * and other reasons to not add 'js=1' param at the end of link
+ * @constant
+ */
+var jsExceptionsRe = /[;?]js=[01]$/;
+
+/**
+ * Add '?js=1' or ';js=1' to the end of every link in the document
+ * that doesn't have 'js' query parameter set already.
+ *
+ * Links with 'js=1' lead to JavaScript version of given action, if it
+ * exists (currently there is only 'blame_incremental' for 'blame')
+ *
+ * To be used as `window.onload` handler
+ *
+ * @globals jsExceptionsRe
+ */
+function fixLinks() {
+ var allLinks = document.getElementsByTagName("a") || document.links;
+ for (var i = 0, len = allLinks.length; i < len; i++) {
+ var link = allLinks[i];
+ if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/;
+ link.href +=
+ (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
+ }
+ }
+}
+
+/* end of detect-javascript.js */
--
1.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH/RFC 2/3] gitweb: Update and improve comments in JavaScript files
2011-03-25 21:46 [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 1/3] gitweb: Split JavaScript for maintability; concatenate on build Jakub Narebski
@ 2011-03-25 21:46 ` Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 3/3] gitweb: Fix parsing of negative fractional timezones in JavaScript Jakub Narebski
2011-03-25 22:03 ` [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript J.H.
3 siblings, 0 replies; 6+ messages in thread
From: Jakub Narebski @ 2011-03-25 21:46 UTC (permalink / raw)
To: git; +Cc: John 'Warthog9' Hawley, Kevin Cernekee, Jakub Narebski
Spell 'neighbor' using American spelling (and not 'neighbour').
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
gitweb/static/js/blame_incremental.js | 22 +++++++++++-----------
gitweb/static/js/common-lib.js | 12 ++++++++----
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/gitweb/static/js/blame_incremental.js b/gitweb/static/js/blame_incremental.js
index 3317390..2067dcd 100644
--- a/gitweb/static/js/blame_incremental.js
+++ b/gitweb/static/js/blame_incremental.js
@@ -8,7 +8,7 @@
* @license GPLv2 or later
*/
-
+/* ============================================================ */
/*
* This code uses DOM methods instead of (nonstandard) innerHTML
* to modify page.
@@ -27,7 +27,7 @@
*/
-/* ============================================================ */
+/* ............................................................ */
/* utility/helper functions (and variables) */
var xhr; // XMLHttpRequest object
@@ -133,7 +133,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
@@ -183,7 +183,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
@@ -204,8 +204,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
@@ -217,14 +217,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) {
@@ -238,7 +238,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));
}
@@ -259,7 +259,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
*/
diff --git a/gitweb/static/js/common-lib.js b/gitweb/static/js/common-lib.js
index 566c98a..33887d7 100644
--- a/gitweb/static/js/common-lib.js
+++ b/gitweb/static/js/common-lib.js
@@ -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.
@@ -126,7 +129,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
--
1.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH/RFC 3/3] gitweb: Fix parsing of negative fractional timezones in JavaScript
2011-03-25 21:46 [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 1/3] gitweb: Split JavaScript for maintability; concatenate on build Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 2/3] gitweb: Update and improve comments in JavaScript files Jakub Narebski
@ 2011-03-25 21:46 ` Jakub Narebski
2011-03-25 22:03 ` [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript J.H.
3 siblings, 0 replies; 6+ messages in thread
From: Jakub Narebski @ 2011-03-25 21:46 UTC (permalink / raw)
To: git; +Cc: John 'Warthog9' Hawley, Kevin Cernekee, Jakub Narebski
Extract converting numerical timezone in the form of '(+|-)HHMM' to
timezoneOffset function, and fix parsing of negative fractional
timezones.
This was used to format timestamps in 'blame_incremental' view.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
gitweb/static/js/common-lib.js | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/gitweb/static/js/common-lib.js b/gitweb/static/js/common-lib.js
index 33887d7..cc72d1e 100644
--- a/gitweb/static/js/common-lib.js
+++ b/gitweb/static/js/common-lib.js
@@ -87,7 +87,24 @@ function createRequestObject() {
* used to extract hours and minutes from timezone info, e.g '-0900'
* @constant
*/
-var tzRe = /^([+-][0-9][0-9])([0-9][0-9])$/;
+var tzRe = /^([-+])([0-9][0-9])([0-9][0-9])$/;
+
+/**
+ * convert numeric timezone +/-ZZZZ to offset from UTC in seconds
+ *
+ * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
+ * @returns {Number} offset from UTC in seconds for timezone
+ *
+ * @globals tzRe
+ */
+function timezoneOffset(timezoneInfo) {
+ var match = tzRe.exec(timezoneInfo);
+ var tz_sign = (match[1] === '-' ? -1 : +1);
+ var tz_hour = parseInt(match[2],10);
+ var tz_min = parseInt(match[3],10);
+
+ return tz_sign*(((tz_hour*60) + tz_min)*60);
+}
/**
* return date in local time formatted in iso-8601 like format
@@ -96,14 +113,11 @@ var tzRe = /^([+-][0-9][0-9])([0-9][0-9])$/;
* @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC'
* @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
* @returns {String} date in local time in iso-8601 like format
- *
- * @globals tzRe
*/
function formatDateISOLocal(epoch, timezoneInfo) {
- var match = tzRe.exec(timezoneInfo);
// date corrected by timezone
var localDate = new Date(1000 * (epoch +
- (parseInt(match[1],10)*3600 + parseInt(match[2],10)*60)));
+ timezoneOffset(timezoneInfo)));
var localDateStr = // e.g. '2005-08-07'
localDate.getUTCFullYear() + '-' +
padLeft(localDate.getUTCMonth()+1, 2, '0') + '-' +
--
1.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript
2011-03-25 21:46 [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript Jakub Narebski
` (2 preceding siblings ...)
2011-03-25 21:46 ` [PATCH/RFC 3/3] gitweb: Fix parsing of negative fractional timezones in JavaScript Jakub Narebski
@ 2011-03-25 22:03 ` J.H.
2011-03-26 11:08 ` Jakub Narebski
3 siblings, 1 reply; 6+ messages in thread
From: J.H. @ 2011-03-25 22:03 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git, Kevin Cernekee
The only thing I would comment on is that we may want to document (for
the build process) a way to force a certain ordering of various files.
Case in point we probably want to force the things like various global
defs (what I'm proposing in the timezone stuff) at the top and let the
function defs go below that.
Other than that this all looks good.
- John 'Warthog9' Hawley
On 03/25/2011 02:46 PM, Jakub Narebski wrote:
> This patch series is inspired by patch by John 'Warthog9' Hawley
>
> [PATCH 1/1] gitweb: javascript ability to adjust time based on timezone
> Message-Id: <1300925335-3212-2-git-send-email-warthog9@eaglescrag.net>
> http://thread.gmane.org/gmane.comp.version-control.git/169384/focus=169882
>
> that added a few new JavaScript files for the new feature that this
> patch implemented.
>
> This is marked as RFC mainly because other patches in series,
> especially the last one fixing bug in gitweb's JavaScript code, should
> be send independently on gitweb.js splitting.
>
> Jakub Narebski (3):
> gitweb: Split JavaScript for maintability; concatenate on build
> gitweb: Update and improve comments in JavaScript files
> gitweb: Fix parsing of negative fractional timezones in JavaScript
>
> .gitignore | 1 +
> gitweb/Makefile | 12 +-
> .../static/{gitweb.js => js/blame_incremental.js} | 216 ++------------------
> gitweb/static/js/common-lib.js | 191 +++++++++++++++++
> gitweb/static/js/detect-javascript.js | 44 ++++
> 5 files changed, 261 insertions(+), 203 deletions(-)
> rename gitweb/static/{gitweb.js => js/blame_incremental.js} (75%)
> create mode 100644 gitweb/static/js/common-lib.js
> create mode 100644 gitweb/static/js/detect-javascript.js
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript
2011-03-25 22:03 ` [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript J.H.
@ 2011-03-26 11:08 ` Jakub Narebski
0 siblings, 0 replies; 6+ messages in thread
From: Jakub Narebski @ 2011-03-26 11:08 UTC (permalink / raw)
To: J.H.; +Cc: git, Kevin Cernekee
On Fri, 25 Mar 2011, J.H. wrote:
> The only thing I would comment on is that we may want to document (for
> the build process) a way to force a certain ordering of various files.
> Case in point we probably want to force the things like various global
> defs (what I'm proposing in the timezone stuff) at the top and let the
> function defs go below that.
Actually I don't think that matters, at least not if JavaScript files
contain only variables and functions, and do not include any code that
is actually run when file is loaded. A very simple test (below)
confirms that.
In JavaScript variable declarations ('var' keyword) and function
definitions ('function' keyword) get "hoisted" at beginning.
> Other than that this all looks good.
Thanks.
-- 8< --
<html>
<head>
<title>JavaScript test</title>
<script>
// -------------------------------------------
// B
var varB = 'varB';
function fooB() {
fooA();
alert('varB='+varB + '; varA='+varA);
return 'fooB';
}
// -------------------------------------------
// A
var varA = 'varA';
function fooA() {
alert('varA='+varA);
return 'fooA';
}
// ===========================================
// main
fooB();
</script>
</head>
<body>
test
</body>
</html>
-- >8 --
--
Jakub Narebski
Poland
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-03-26 11:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-25 21:46 [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 1/3] gitweb: Split JavaScript for maintability; concatenate on build Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 2/3] gitweb: Update and improve comments in JavaScript files Jakub Narebski
2011-03-25 21:46 ` [PATCH/RFC 3/3] gitweb: Fix parsing of negative fractional timezones in JavaScript Jakub Narebski
2011-03-25 22:03 ` [PATCH/RFC 0/3] gitweb: Split gitweb.js, improve JavaScript J.H.
2011-03-26 11:08 ` Jakub Narebski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).