X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..6e39d509471fe9b4e2660e0d1631b350d0c66f40:/src/util/Format.js diff --git a/src/util/Format.js b/src/util/Format.js index 747ed1a5..80659aa4 100644 --- a/src/util/Format.js +++ b/src/util/Format.js @@ -1,5 +1,5 @@ /*! - * Ext JS Library 3.0.3 + * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license @@ -10,7 +10,11 @@ * @singleton */ Ext.util.Format = function(){ - var trimRe = /^\s+|\s+$/g; + var trimRe = /^\s+|\s+$/g, + stripTagsRE = /<\/?[^>]+>/gi, + stripScriptsRe = /(?:)((\n|\r|.)*?)(?:<\/script>)/ig, + nl2brRe = /\r?\n/g; + return { /** * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length @@ -22,8 +26,8 @@ Ext.util.Format = function(){ ellipsis : function(value, len, word){ if(value && value.length > len){ if(word){ - var vs = value.substr(0, len - 2); - var index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?')); + var vs = value.substr(0, len - 2), + index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?')); if(index == -1 || index < (len - 15)){ return value.substr(0, len - 3) + "..."; }else{ @@ -140,10 +144,10 @@ Ext.util.Format = function(){ v = (Math.round((v-0)*100))/100; v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v); v = String(v); - var ps = v.split('.'); - var whole = ps[0]; - var sub = ps[1] ? '.'+ ps[1] : '.00'; - var r = /(\d+)(\d{3})/; + var ps = v.split('.'), + whole = ps[0], + sub = ps[1] ? '.'+ ps[1] : '.00', + r = /(\d+)(\d{3})/; while (r.test(whole)) { whole = whole.replace(r, '$1' + ',' + '$2'); } @@ -180,9 +184,6 @@ Ext.util.Format = function(){ return Ext.util.Format.date(v, format); }; }, - - // private - stripTagsRE : /<\/?[^>]+>/gi, /** * Strips all HTML tags @@ -190,18 +191,16 @@ Ext.util.Format = function(){ * @return {String} The stripped text */ stripTags : function(v){ - return !v ? v : String(v).replace(this.stripTagsRE, ""); + return !v ? v : String(v).replace(stripTagsRE, ""); }, - stripScriptsRe : /(?:)((\n|\r|.)*?)(?:<\/script>)/ig, - /** * Strips all script tags * @param {Mixed} value The text from which to strip script tags * @return {String} The stripped text */ stripScripts : function(v){ - return !v ? v : String(v).replace(this.stripScriptsRe, ""); + return !v ? v : String(v).replace(stripScriptsRe, ""); }, /** @@ -350,7 +349,7 @@ Ext.util.Format = function(){ * @return {String} The string with embedded <br/> tags in place of newlines. */ nl2br : function(v){ - return v === undefined || v === null ? '' : v.replace(/\n/g, '
'); + return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '
'); } } -}(); \ No newline at end of file +}();