luci-base: cbi.js: string formatting fixes
* Fix left and right justify/padding in formats * Do not emit decimal numbers for small values in %m format Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
5cfad4338f
commit
a860de860a
1 changed files with 15 additions and 3 deletions
|
@ -1332,6 +1332,8 @@ String.prototype.format = function()
|
||||||
pad = leftpart.substr(1,1);
|
pad = leftpart.substr(1,1);
|
||||||
else if (pPad)
|
else if (pPad)
|
||||||
pad = pPad;
|
pad = pPad;
|
||||||
|
else
|
||||||
|
pad = ' ';
|
||||||
|
|
||||||
var justifyRight = true;
|
var justifyRight = true;
|
||||||
if (pJustify && pJustify === "-")
|
if (pJustify && pJustify === "-")
|
||||||
|
@ -1437,12 +1439,22 @@ String.prototype.format = function()
|
||||||
for (i = 0; (i < units.length) && (val > mf); i++)
|
for (i = 0; (i < units.length) && (val > mf); i++)
|
||||||
val /= mf;
|
val /= mf;
|
||||||
|
|
||||||
subst = val.toFixed(pr) + ' ' + units[i];
|
subst = (i ? val.toFixed(pr) : val) + units[i];
|
||||||
|
pMinLength = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMinLength) {
|
||||||
|
subst = subst.toString();
|
||||||
|
for (var i = subst.length; i < pMinLength; i++)
|
||||||
|
if (pJustify == '-')
|
||||||
|
subst = subst + ' ';
|
||||||
|
else
|
||||||
|
subst = pad + subst;
|
||||||
|
}
|
||||||
|
|
||||||
out += leftpart + subst;
|
out += leftpart + subst;
|
||||||
str = str.substr(m.length);
|
str = str.substr(m.length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue