]> Lady’s Gitweb - Gitweb/commitdiff
gitweb.js: fix padLeftStr() and its usage
authorStephen Boyd <redacted>
Wed, 25 Nov 2009 03:51:40 +0000 (19:51 -0800)
committerLady <redacted>
Mon, 6 Apr 2026 04:50:39 +0000 (00:50 -0400)
It seems that in Firefox-3.5 inserting &nbsp; with javascript inserts the
literal &nbsp; instead of a space. Fix this by inserting the unicode
representation for &nbsp; instead.

Also fix the off-by-one error in the padding calculation that was
causing one less space to be inserted than was requested by the caller.

Signed-off-by: Stephen Boyd <redacted>
Cc: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.js

index ff2d53365b02fd70522a8fcef202dbda902aeb09b31a5da592fab457167e28f4..0c0b6a6b2c10ce278bec52f1edcd46a79ec7f397ed35c5e31ad819cb352e1b7b 100644 (file)
--- a/gitweb.js
+++ b/gitweb.js
@@ -64,19 +64,19 @@ function fixLinks() {
 
 /**
  * pad number N with nonbreakable spaces on the left, to WIDTH characters
- * example: padLeftStr(12, 3, '&nbsp;') == '&nbsp;12'
- *          ('&nbsp;' is nonbreakable space)
+ * 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. '&nbsp;'
+ * @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 > 1) {
+       while (width > 0) {
                prefix += str;
                width--;
        }
@@ -192,7 +192,7 @@ function updateProgressInfo() {
 
        if (div_progress_info) {
                div_progress_info.firstChild.data  = blamedLines + ' / ' + totalLines +
-                       ' (' + padLeftStr(percentage, 3, '&nbsp;') + '%)';
+                       ' (' + padLeftStr(percentage, 3, '\u00A0') + '%)';
        }
 
        if (div_progress_bar) {
This page took 0.246455 seconds and 4 git commands to generate.