git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: John 'Warthog9' Hawley <warthog9@eaglescrag.net>,
	Kevin Cernekee <cernekee@gmail.com>,
	Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH/RFC 03/11] gitweb.js: Provide default values for padding in padLeftStr and padLeft
Date: Sun, 10 Apr 2011 00:49:18 +0200	[thread overview]
Message-ID: <1302389366-21515-4-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1302389366-21515-1-git-send-email-jnareb@gmail.com>

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.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
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(-)

diff --git a/gitweb/static/js/lib/common-lib.js b/gitweb/static/js/lib/common-lib.js
index 6a6d200..c45454e 100644
--- a/gitweb/static/js/lib/common-lib.js
+++ b/gitweb/static/js/lib/common-lib.js
@@ -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;
 	}
-- 
1.7.3

  parent reply	other threads:[~2011-04-09 22:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-09 22:49 [PATCH 00/11] gitweb: Change timezone Jakub Narebski
2011-04-09 22:49 ` [PATCH 01/11] gitweb: Split JavaScript for maintability, combining on build Jakub Narebski
2011-04-09 22:49 ` [PATCH 02/11] gitweb.js: Update and improve comments in JavaScript files Jakub Narebski
2011-04-09 22:49 ` Jakub Narebski [this message]
2011-04-09 22:49 ` [PATCH 04/11] gitweb.js: Extract and improve datetime handling Jakub Narebski
2011-04-09 22:49 ` [PATCH 05/11] gitweb.js: Introduce gitweb/static/js/lib/cookies.js Jakub Narebski
2011-04-09 22:49 ` [PATCH 06/11] gitweb.js: Provide getElementsByClassName method (if it not exists) Jakub Narebski
2011-04-09 22:49 ` [PATCH 07/11] gitweb: Refactor generating of long dates into format_timestamp_html Jakub Narebski
2011-04-09 22:49 ` [RFC/PATCH 08/11] gitweb: Unify the way long timestamp is displayed Jakub Narebski
2011-04-09 22:49 ` [PATCH 09/11] gitweb: JavaScript ability to adjust time based on timezone Jakub Narebski
2011-04-09 22:49 ` [PATCH/RFC 10/11] gitweb.js: Add UI for selecting common timezone to display dates Jakub Narebski
2011-04-10  9:36   ` Jakub Narebski
2011-04-10 14:39     ` Jakub Narebski
2011-04-10 15:10   ` Jakub Narebski
2011-04-09 22:49 ` [PATCH/RFC 11/11] gitweb: Make JavaScript ability to adjust timezones configurable Jakub Narebski
2011-04-12  1:19 ` [PATCH 00/11] gitweb: Change timezone Kevin Cernekee
2011-04-12 12:44   ` Jakub Narebski
2011-04-12 13:24     ` [PATCHv2 10/11] gitweb.js: Add UI for selecting common timezone to display dates Jakub Narebski
2011-04-12 13:25     ` [PATCHv2 11/11] gitweb: Make JavaScript ability to adjust timezones configurable Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302389366-21515-4-git-send-email-jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=cernekee@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=warthog9@eaglescrag.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).