X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/source/Format.html diff --git a/docs/source/Format.html b/docs/source/Format.html index 2e44a03d..04f7462d 100644 --- a/docs/source/Format.html +++ b/docs/source/Format.html @@ -1,4 +1,21 @@ -
/**
+
+
+
+
+ The source code
+
+
+
+
+
+
+ /**
* @class Ext.util.Format
This class is a centralized place for formatting functions inside the library. It includes
@@ -13,7 +30,7 @@ Options include:
- currenyPrecision
- currencySign
- currencyAtEnd
-This class also uses the default date format defined here: {@link Ext.date#defaultFormat}.
+This class also uses the default date format defined here: {@link Ext.Date#defaultFormat}.
__Using with renderers__
There are two helper functions that return a new function that can be used in conjunction with
@@ -64,7 +81,7 @@ XTemplates can also directly use Ext.util.Format functions:
I18NFormatCleanRe;
Ext.apply(UtilFormat, {
- /**
+ /**
* @type String
* @property thousandSeparator
* <p>The character that the {@link #number} function uses as a thousand separator.</p>
@@ -72,7 +89,7 @@ XTemplates can also directly use Ext.util.Format functions:
*/
thousandSeparator: ',',
- /**
+ /**
* @type String
* @property decimalSeparator
* <p>The character that the {@link #number} function uses as a decimal point.</p>
@@ -80,7 +97,7 @@ XTemplates can also directly use Ext.util.Format functions:
*/
decimalSeparator: '.',
- /**
+ /**
* @type Number
* @property currencyPrecision
* <p>The number of decimal places that the {@link #currency} function displays.</p>
@@ -88,7 +105,7 @@ XTemplates can also directly use Ext.util.Format functions:
*/
currencyPrecision: 2,
- /**
+ /**
* @type String
* @property currencySign
* <p>The currency sign that the {@link #currency} function displays.</p>
@@ -96,7 +113,7 @@ XTemplates can also directly use Ext.util.Format functions:
*/
currencySign: '$',
- /**
+ /**
* @type Boolean
* @property currencyAtEnd
* <p>This may be set to <code>true</code> to make the {@link #currency} function
@@ -105,7 +122,7 @@ XTemplates can also directly use Ext.util.Format functions:
*/
currencyAtEnd: false,
- /**
+ /**
* Checks a reference and converts it to empty string if it is undefined
* @param {Mixed} value Reference to check
* @return {Mixed} Empty string if converted, otherwise the original value
@@ -114,7 +131,7 @@ XTemplates can also directly use Ext.util.Format functions:
return value !== undefined ? value : "";
},
- /**
+ /**
* Checks a reference and converts it to the default value if it's empty
* @param {Mixed} value Reference to check
* @param {String} defaultValue The value to insert of it's undefined (defaults to "")
@@ -124,7 +141,7 @@ XTemplates can also directly use Ext.util.Format functions:
return value !== undefined && value !== '' ? value : defaultValue;
},
- /**
+ /**
* Returns a substring from within an original string
* @param {String} value The original text
* @param {Number} start The start index of the substring
@@ -135,7 +152,7 @@ XTemplates can also directly use Ext.util.Format functions:
return String(value).substr(start, length);
},
- /**
+ /**
* Converts a string to all lower case letters
* @param {String} value The text to convert
* @return {String} The converted text
@@ -144,7 +161,7 @@ XTemplates can also directly use Ext.util.Format functions:
return String(value).toLowerCase();
},
- /**
+ /**
* Converts a string to all upper case letters
* @param {String} value The text to convert
* @return {String} The converted text
@@ -153,7 +170,7 @@ XTemplates can also directly use Ext.util.Format functions:
return String(value).toUpperCase();
},
- /**
+ /**
* Format a number as US currency
* @param {Number/String} value The numeric value to format
* @return {String} The formatted currency string
@@ -162,7 +179,7 @@ XTemplates can also directly use Ext.util.Format functions:
return UtilFormat.currency(v, '$', 2);
},
- /**
+ /**
* Format a number as a currency
* @param {Number/String} value The numeric value to format
* @param {String} sign The currency sign to use (defaults to {@link #currencySign})
@@ -192,7 +209,7 @@ XTemplates can also directly use Ext.util.Format functions:
}
},
- /**
+ /**
* Formats the passed date using the specified format pattern.
* @param {String/Date} value The value to format. If a string is passed, it is converted to a Date by the Javascript
* Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method.
@@ -209,7 +226,7 @@ XTemplates can also directly use Ext.util.Format functions:
return Ext.Date.dateFormat(v, format || Ext.Date.defaultFormat);
},
- /**
+ /**
* Returns a date rendering function that can be reused to apply a date format multiple times efficiently
* @param {String} format Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}.
* @return {Function} The date formatting function
@@ -220,7 +237,7 @@ XTemplates can also directly use Ext.util.Format functions:
};
},
- /**
+ /**
* Strips all HTML tags
* @param {Mixed} value The text from which to strip tags
* @return {String} The stripped text
@@ -229,7 +246,7 @@ XTemplates can also directly use Ext.util.Format functions:
return !v ? v : String(v).replace(stripTagsRE, "");
},
- /**
+ /**
* Strips all script tags
* @param {Mixed} value The text from which to strip script tags
* @return {String} The stripped text
@@ -238,7 +255,7 @@ XTemplates can also directly use Ext.util.Format functions:
return !v ? v : String(v).replace(stripScriptsRe, "");
},
- /**
+ /**
* Simple format for a file size (xxx bytes, xxx KB, xxx MB)
* @param {Number/String} size The numeric value to format
* @return {String} The formatted file size
@@ -253,11 +270,12 @@ XTemplates can also directly use Ext.util.Format functions:
}
},
- /**
+ /**
* It does simple math for use in a template, for example:<pre><code>
* var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
* </code></pre>
* @return {Function} A function that operates on the passed value.
+ * @method
*/
math : function(){
var fns = {};
@@ -270,7 +288,7 @@ XTemplates can also directly use Ext.util.Format functions:
};
}(),
- /**
+ /**
* Rounds the passed number to the required decimal precision.
* @param {Number/String} value The numeric value to round.
* @param {Number} precision The number of decimal places to which to round the first parameter's value.
@@ -285,7 +303,7 @@ XTemplates can also directly use Ext.util.Format functions:
return result;
},
- /**
+ /**
* <p>Formats the passed number according to the passed format string.</p>
* <p>The number of digits after the decimal separator character specifies the number of
* decimal places in the resulting string. The <u>local-specific</u> decimal character is used in the result.</p>
@@ -314,8 +332,7 @@ XTemplates can also directly use Ext.util.Format functions:
* @param {String} format The way you would like to format this text.
* @return {String} The formatted number.
*/
- number:
- function(v, formatString) {
+ number: function(v, formatString) {
if (!formatString) {
return v;
}
@@ -394,11 +411,20 @@ XTemplates can also directly use Ext.util.Format functions:
fnum = psplit[0] + dec + psplit[1];
}
}
+
+ if (neg) {
+ /*
+ * Edge case. If we have a very small negative number it will get rounded to 0,
+ * however the initial check at the top will still report as negative. Replace
+ * everything but 1-9 and check if the string is empty to determine a 0 value.
+ */
+ neg = fnum.replace(/[^1-9]/g, '') !== '';
+ }
return (neg ? '-' : '') + formatString.replace(/[\d,?\.?]+/, fnum);
},
- /**
+ /**
* Returns a number rendering function that can be reused to apply a number format multiple times efficiently
* @param {String} format Any valid number format string for {@link #number}
* @return {Function} The number formatting function
@@ -409,7 +435,7 @@ XTemplates can also directly use Ext.util.Format functions:
};
},
- /**
+ /**
* Selectively do a plural form of a word based on a numeric value. For example, in a template,
* {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments"
* if the value is 0 or greater than 1.
@@ -421,7 +447,7 @@ XTemplates can also directly use Ext.util.Format functions:
return v +' ' + (v == 1 ? s : (p ? p : s+'s'));
},
- /**
+ /**
* Converts newline characters to the HTML tag <br/>
* @param {String} The string value to format.
* @return {String} The string with embedded <br/> tags in place of newlines.
@@ -430,45 +456,52 @@ XTemplates can also directly use Ext.util.Format functions:
return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');
},
- /**
+ /**
* Capitalize the given string. See {@link Ext.String#capitalize}.
+ * @method
*/
capitalize: Ext.String.capitalize,
- /**
+ /**
* Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length.
* See {@link Ext.String#ellipsis}.
+ * @method
*/
ellipsis: Ext.String.ellipsis,
- /**
+ /**
* Formats to a string. See {@link Ext.String#format}
+ * @method
*/
format: Ext.String.format,
- /**
+ /**
* Convert certain characters (&, <, >, and ') from their HTML character equivalents.
- * See {@link Ext.string#htmlDecode}.
+ * See {@link Ext.String#htmlDecode}.
+ * @method
*/
htmlDecode: Ext.String.htmlDecode,
- /**
+ /**
* Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
* See {@link Ext.String#htmlEncode}.
+ * @method
*/
htmlEncode: Ext.String.htmlEncode,
- /**
+ /**
* Adds left padding to a string. See {@link Ext.String#leftPad}
+ * @method
*/
leftPad: Ext.String.leftPad,
- /**
+ /**
* Trims any whitespace from either side of a string. See {@link Ext.String#trim}.
+ * @method
*/
trim : Ext.String.trim,
- /**
+ /**
* Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
* (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
* @param {Number|String} v The encoded margins
@@ -500,7 +533,7 @@ XTemplates can also directly use Ext.util.Format functions:
};
},
- /**
+ /**
* Escapes the passed string for use in a regular expression
* @param {String} str
* @return {String}
@@ -510,4 +543,6 @@ XTemplates can also directly use Ext.util.Format functions:
}
});
})();
-
\ No newline at end of file
+
+
+