From f5a9dd6812f84d2d38af6568567147e7fbda6af7 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 16 Dec 2009 00:28:24 +0000 Subject: [PATCH] Missing file from previous commit: Zotero.Utilities.ellipsize(str, len, countChars) --- chrome/content/zotero/xpcom/utilities.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 95aa00905..4dcda647d 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -528,6 +528,24 @@ Zotero.Utilities.prototype.lpad = function(string, pad, length) { } +/** + * Shorten and add an ellipsis to a string if necessary + * + * @param {String} str + * @param {Integer} len + * @param {Boolean} [countChars=false] + */ +Zotero.Utilities.prototype.ellipsize = function (str, len, countChars) { + if (!len) { + throw ("Length not specified in Zotero.Utilities.ellipsize()"); + } + if (str.length > len) { + return str.substr(0, len) + '...' + (countChars ? ' (' + str.length + ' chars)' : ''); + } + return str; +} + + /** * Port of PHP's number_format() *