+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.util.Format\r
- * Reusable data formatting functions\r
- * @singleton\r
- */\r
-Ext.util.Format = function(){\r
- var trimRe = /^\s+|\s+$/g;\r
- return {\r
- /**\r
- * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length\r
- * @param {String} value The string to truncate\r
- * @param {Number} length The maximum length to allow before truncating\r
- * @return {String} The converted text\r
- */\r
- ellipsis : function(value, len){\r
- if(value && value.length > len){\r
- return value.substr(0, len-3)+"...";\r
- }\r
- return value;\r
- },\r
-\r
- /**\r
- * Checks a reference and converts it to empty string if it is undefined\r
- * @param {Mixed} value Reference to check\r
- * @return {Mixed} Empty string if converted, otherwise the original value\r
- */\r
- undef : function(value){\r
- return value !== undefined ? value : "";\r
- },\r
-\r
- /**\r
- * Checks a reference and converts it to the default value if it's empty\r
- * @param {Mixed} value Reference to check\r
- * @param {String} defaultValue The value to insert of it's undefined (defaults to "")\r
- * @return {String}\r
- */\r
- defaultValue : function(value, defaultValue){\r
- return value !== undefined && value !== '' ? value : defaultValue;\r
- },\r
-\r
- /**\r
- * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.\r
- * @param {String} value The string to encode\r
- * @return {String} The encoded text\r
- */\r
- htmlEncode : function(value){\r
- return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);\r
- },\r
-\r
- /**\r
- * Convert certain characters (&, <, >, and ') from their HTML character equivalents.\r
- * @param {String} value The string to decode\r
- * @return {String} The decoded text\r
- */\r
- htmlDecode : function(value){\r
- return !value ? value : String(value).replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"').replace(/&/g, "&");\r
- },\r
-\r
- /**\r
- * Trims any whitespace from either side of a string\r
- * @param {String} value The text to trim\r
- * @return {String} The trimmed text\r
- */\r
- trim : function(value){\r
- return String(value).replace(trimRe, "");\r
- },\r
-\r
- /**\r
- * Returns a substring from within an original string\r
- * @param {String} value The original text\r
- * @param {Number} start The start index of the substring\r
- * @param {Number} length The length of the substring\r
- * @return {String} The substring\r
- */\r
- substr : function(value, start, length){\r
- return String(value).substr(start, length);\r
- },\r
-\r
- /**\r
- * Converts a string to all lower case letters\r
- * @param {String} value The text to convert\r
- * @return {String} The converted text\r
- */\r
- lowercase : function(value){\r
- return String(value).toLowerCase();\r
- },\r
-\r
- /**\r
- * Converts a string to all upper case letters\r
- * @param {String} value The text to convert\r
- * @return {String} The converted text\r
- */\r
- uppercase : function(value){\r
- return String(value).toUpperCase();\r
- },\r
-\r
- /**\r
- * Converts the first character only of a string to upper case\r
- * @param {String} value The text to convert\r
- * @return {String} The converted text\r
- */\r
- capitalize : function(value){\r
- return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();\r
- },\r
-\r
- // private\r
- call : function(value, fn){\r
- if(arguments.length > 2){\r
- var args = Array.prototype.slice.call(arguments, 2);\r
- args.unshift(value);\r
- return eval(fn).apply(window, args);\r
- }else{\r
- return eval(fn).call(window, value);\r
- }\r
- },\r
-\r
- /**\r
- * Format a number as US currency\r
- * @param {Number/String} value The numeric value to format\r
- * @return {String} The formatted currency string\r
- */\r
- usMoney : function(v){\r
- v = (Math.round((v-0)*100))/100;\r
- v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);\r
- v = String(v);\r
- var ps = v.split('.');\r
- var whole = ps[0];\r
- var sub = ps[1] ? '.'+ ps[1] : '.00';\r
- var r = /(\d+)(\d{3})/;\r
- while (r.test(whole)) {\r
- whole = whole.replace(r, '$1' + ',' + '$2');\r
- }\r
- v = whole + sub;\r
- if(v.charAt(0) == '-'){\r
- return '-$' + v.substr(1);\r
- }\r
- return "$" + v;\r
- },\r
-\r
- /**\r
- * Parse a value into a formatted date using the specified format pattern.\r
- * @param {String/Date} value The value to format (Strings must conform to the format expected by the javascript Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method)\r
- * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')\r
- * @return {String} The formatted date string\r
- */\r
- date : function(v, format){\r
- if(!v){\r
- return "";\r
- }\r
- if(!Ext.isDate(v)){\r
- v = new Date(Date.parse(v));\r
- }\r
- return v.dateFormat(format || "m/d/Y");\r
- },\r
-\r
- /**\r
- * Returns a date rendering function that can be reused to apply a date format multiple times efficiently\r
- * @param {String} format Any valid date format string\r
- * @return {Function} The date formatting function\r
- */\r
- dateRenderer : function(format){\r
- return function(v){\r
- return Ext.util.Format.date(v, format);\r
- };\r
- },\r
-\r
- // private\r
- stripTagsRE : /<\/?[^>]+>/gi,\r
- \r
- /**\r
- * Strips all HTML tags\r
- * @param {Mixed} value The text from which to strip tags\r
- * @return {String} The stripped text\r
- */\r
- stripTags : function(v){\r
- return !v ? v : String(v).replace(this.stripTagsRE, "");\r
- },\r
-\r
- // private\r
- stripScriptsRe : /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,\r
-\r
- /**\r
- * Strips all script tags\r
- * @param {Mixed} value The text from which to strip script tags\r
- * @return {String} The stripped text\r
- */\r
- stripScripts : function(v){\r
- return !v ? v : String(v).replace(this.stripScriptsRe, "");\r
- },\r
-\r
- /**\r
- * Simple format for a file size (xxx bytes, xxx KB, xxx MB)\r
- * @param {Number/String} size The numeric value to format\r
- * @return {String} The formatted file size\r
- */\r
- fileSize : function(size){\r
- if(size < 1024) {\r
- return size + " bytes";\r
- } else if(size < 1048576) {\r
- return (Math.round(((size*10) / 1024))/10) + " KB";\r
- } else {\r
- return (Math.round(((size*10) / 1048576))/10) + " MB";\r
- }\r
- },\r
-\r
- math : function(){\r
- var fns = {};\r
- return function(v, a){\r
- if(!fns[a]){\r
- fns[a] = new Function('v', 'return v ' + a + ';');\r
- }\r
- return fns[a](v);\r
- }\r
- }(),\r
-\r
- /**\r
- * Converts newline characters to the HTML tag <br/>\r
- * @param {String} The string value to format.\r
- * @return {String} The string with embedded <br/> tags in place of newlines.\r
- */\r
- nl2br : function(v){\r
- return v === undefined || v === null ? '' : v.replace(/\n/g, '<br/>');\r
- }\r
- };\r
-}();
\ No newline at end of file