Missing file from previous commit: Zotero.Utilities.ellipsize(str, len, countChars)

This commit is contained in:
Dan Stillman 2009-12-16 00:28:24 +00:00
parent d1d70d3df8
commit f5a9dd6812

View file

@ -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()
*