diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-03-13 11:12:11 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-03-13 11:12:11 +0000 |
commit | a8688343d6dcddfaeae2ed3c696c752ab276a23e (patch) | |
tree | 118a107d6edda243db05c15e259de1f5463db719 /libs/web/htdocs/luci-static/resources/cbi.js | |
parent | 9836e949a58484a83d40a10570c3dab919770d6a (diff) |
libs/web: add %m pattern to String.format()
Diffstat (limited to 'libs/web/htdocs/luci-static/resources/cbi.js')
-rw-r--r-- | libs/web/htdocs/luci-static/resources/cbi.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js index be0a5a8d70..41e7512062 100644 --- a/libs/web/htdocs/luci-static/resources/cbi.js +++ b/libs/web/htdocs/luci-static/resources/cbi.js @@ -907,7 +907,7 @@ if( ! String.format ) var str = arguments[0]; var out = ''; - var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t))/; + var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/; var a = b = [], numSubstitutions = 0, numMatches = 0; while( a = re.exec(str) ) @@ -1026,6 +1026,20 @@ if( ! String.format ) : String.format('%dh %dm %ds', th, tm, ts); break; + + case 'm': + var mf = pMinLength ? parseInt(pMinLength) : 1000; + var pr = pPrecision ? Math.floor(10*parseFloat('0'+pPrecision)) : 2; + + var i = 0; + var val = (param || 0); + var units = [ '', 'K', 'M', 'G', 'T', 'P', 'E' ]; + + for (i = 0; (i < units.length) && (val > mf); i++) + val /= mf; + + subst = val.toFixed(pr) + ' ' + units[i]; + break; } } } |