summaryrefslogtreecommitdiffhomepage
path: root/libs/web
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-12-01 20:53:29 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-12-01 20:53:29 +0000
commit9abe328f9a85db356d0be69887d594edaa748c34 (patch)
tree33aa8992b78da9df882d97a7b201470ebbec983f /libs/web
parent438df402b04b9a086c6cdecc48b2f72473c6d5a5 (diff)
libs/web: add %t format to String.format(), fix float formatting
Diffstat (limited to 'libs/web')
-rw-r--r--libs/web/htdocs/luci-static/resources/cbi.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js
index 62dada464e..280d476be5 100644
--- a/libs/web/htdocs/luci-static/resources/cbi.js
+++ b/libs/web/htdocs/luci-static/resources/cbi.js
@@ -90,6 +90,7 @@ var cbi_validators = {
(RegExp.$2 ? ':' + RegExp.$2 : '');
}
+ window.status = addr;
return (addr.match(/^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/) != null);
}
}
@@ -778,7 +779,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))/;
+ var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t))/;
var a = b = [], numSubstitutions = 0, numMatches = 0;
while( a = re.exec(str) )
@@ -839,7 +840,7 @@ if( ! String.format )
case 'f':
subst = (precision > -1)
- ? Math.round((parseFloat(param) || 0.0) * Math.pow(10, precision)) / Math.pow(10, precision)
+ ? ((parseFloat(param) || 0.0)).toFixed(precision)
: (parseFloat(param) || 0.0);
break;
@@ -870,6 +871,33 @@ if( ! String.format )
case 'j':
subst = String.serialize(param);
break;
+
+ case 't':
+ var td = 0;
+ var th = 0;
+ var tm = 0;
+ var ts = (param || 0);
+
+ if (ts > 60) {
+ tm = Math.floor(ts / 60);
+ ts = (ts % 60);
+ }
+
+ if (tm > 60) {
+ th = Math.floor(tm / 60);
+ tm = (tm % 60);
+ }
+
+ if (th > 24) {
+ td = Math.floor(th / 24);
+ th = (th % 24);
+ }
+
+ subst = (td > 0)
+ ? String.format('%dd %dh %dm %ds', td, th, tm, ts)
+ : String.format('%dh %dm %ds', th, tm, ts);
+
+ break;
}
}
}