2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
18 var cbi_validators
= {
20 'integer': function(v
)
22 return (v
.match(/^-?[0-9]+$/) != null);
25 'uinteger': function(v
)
27 return (cbi_validators
.integer(v
) && (v
>= 0));
32 return !isNaN(parseFloat(v
));
37 return (cbi_validators
['float'](v
) && (v
>= 0));
42 return cbi_validators
.ip4addr(v
) || cbi_validators
.ip6addr(v
);
45 'neg_ipaddr': function(v
)
47 return cbi_validators
.ip4addr(v
.replace(/^\s*!/, "")) || cbi_validators
.ip6addr(v
.replace(/^\s*!/, ""));
50 'ip4addr': function(v
)
52 if( v
.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)(\/(\d+))?$/) )
54 return (RegExp
.$1 >= 0) && (RegExp
.$1 <= 255) &&
55 (RegExp
.$2 >= 0) && (RegExp
.$2 <= 255) &&
56 (RegExp
.$3 >= 0) && (RegExp
.$3 <= 255) &&
57 (RegExp
.$4 >= 0) && (RegExp
.$4 <= 255) &&
58 (!RegExp
.$5 || ((RegExp
.$6 >= 0) && (RegExp
.$6 <= 32)))
65 'neg_ip4addr': function(v
)
67 return cbi_validators
.ip4addr(v
.replace(/^\s*!/, ""));
70 'ip6addr': function(v
)
72 if( v
.match(/^([a-fA-F0-9:.]+)(\/(\d+))?$/) )
74 if( !RegExp
.$2 || ((RegExp
.$3 >= 0) && (RegExp
.$3 <= 128)) )
83 if( addr
.indexOf('.') > 0 )
85 var off
= addr
.lastIndexOf(':');
87 if( !(off
&& cbi_validators
.ip4addr(addr
.substr(off
+1))) )
90 addr
= addr
.substr(0, off
) + ':0:0';
93 if( addr
.indexOf('::') >= 0 )
98 for( var i
= 1; i
< (addr
.length
-1); i
++ )
99 if( addr
.charAt(i
) == ':' )
105 for( var i
= 0; i
< (7 - colons
); i
++ )
108 if (addr
.match(/^(.*?)::(.*?)$/))
109 addr
= (RegExp
.$1 ? RegExp
.$1 + ':' : '') + fill
+
110 (RegExp
.$2 ? ':' + RegExp
.$2 : '');
113 return (addr
.match(/^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/) != null);
122 return cbi_validators
.integer(v
) && (v
>= 0) && (v
<= 65535);
125 'portrange': function(v
)
127 if( v
.match(/^(\d+)-(\d+)$/) )
132 return cbi_validators
.port(p1
) &&
133 cbi_validators
.port(p2
) &&
134 (parseInt(p1
) <= parseInt(p2
))
139 return cbi_validators
.port(v
);
143 'macaddr': function(v
)
145 return (v
.match(/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/) != null);
150 return cbi_validators
.hostname(v
) || cbi_validators
.ipaddr(v
);
153 'hostname': function(v
)
156 return (v
.match(/^[a-zA-Z0-9]+$/) != null ||
157 v
.match(/^[a-zA-Z0-9][a-zA-Z0-9\-.]*[a-zA-Z0-9]$/) != null);
162 'network': function(v
)
164 return cbi_validators
.uciname(v
) || cbi_validators
.host(v
);
167 'wpakey': function(v
)
170 return (v
.match(/^[a-fA-F0-9]{64}$/) != null);
172 return (v
.length
>= 8) && (v
.length
<= 63);
175 'wepkey': function(v
)
177 if( v
.substr(0,2) == 's:' )
180 if( (v
.length
== 10) || (v
.length
== 26) )
181 return (v
.match(/^[a-fA-F0-9]{10,26}$/) != null);
183 return (v
.length
== 5) || (v
.length
== 13);
186 'uciname': function(v
)
188 return (v
.match(/^[a-zA-Z0-9_]+$/) != null);
191 'neg_network_ip4addr': function(v
)
193 v
= v
.replace(/^\s*!/, "");
194 return cbi_validators
.uciname(v
) || cbi_validators
.ip4addr(v
);
197 'range': function(v
, args
)
199 var min
= parseInt(args
[0]);
200 var max
= parseInt(args
[1]);
201 var val
= parseInt(v
);
203 if (!isNaN(min
) && !isNaN(max
) && !isNaN(val
))
204 return ((val
>= min
) && (val
<= max
));
209 'min': function(v
, args
)
211 var min
= parseInt(args
[0]);
212 var val
= parseInt(v
);
214 if (!isNaN(min
) && !isNaN(val
))
220 'max': function(v
, args
)
222 var max
= parseInt(args
[0]);
223 var val
= parseInt(v
);
225 if (!isNaN(max
) && !isNaN(val
))
231 'neg': function(v
, args
)
233 if (args
[0] && typeof cbi_validators
[args
[0]] == "function")
234 return cbi_validators
[args
[0]](v
.replace(/^\s*!\s*/, ''));
239 'list': function(v
, args
)
241 var cb
= cbi_validators
[args
[0] || 'string'];
242 if (typeof cb
== "function")
244 var cbargs
= args
.slice(1);
245 var values
= v
.match(/[^\s]+/g);
247 for (var i
= 0; i
< values
.length
; i
++)
248 if (!cb(values
[i
], cbargs
))
259 function cbi_d_add(field
, dep
, next
) {
260 var obj
= document
.getElementById(field
);
263 for (var i
=0; i
<cbi_d
.length
; i
++) {
264 if (cbi_d
[i
].id
== field
) {
273 "parent": obj
.parentNode
.id
,
277 cbi_d
.unshift(entry
);
283 function cbi_d_checkvalue(target
, ref
) {
284 var t
= document
.getElementById(target
);
288 var tl
= document
.getElementsByName(target
);
290 if( tl
.length
> 0 && tl
[0].type
== 'radio' )
291 for( var i
= 0; i
< tl
.length
; i
++ )
292 if( tl
[i
].checked
) {
297 value
= value
? value
: "";
298 } else if (!t
.value
) {
303 if (t
.type
== "checkbox") {
304 value
= t
.checked
? value
: "";
308 return (value
== ref
)
311 function cbi_d_check(deps
) {
314 for (var i
=0; i
<deps
.length
; i
++) {
317 for (var j
in deps
[i
]) {
318 if (j
== "!reverse") {
320 } else if (j
== "!default") {
324 istat
= (istat
&& cbi_d_checkvalue(j
, deps
[i
][j
]))
334 function cbi_d_update() {
336 for (var i
=0; i
<cbi_d
.length
; i
++) {
337 var entry
= cbi_d
[i
];
338 var next
= document
.getElementById(entry
.next
)
339 var node
= document
.getElementById(entry
.id
)
340 var parent
= document
.getElementById(entry
.parent
)
342 if (node
&& node
.parentNode
&& !cbi_d_check(entry
.deps
)) {
343 node
.parentNode
.removeChild(node
);
346 cbi_c
[entry
.parent
]--;
347 } else if ((!node
|| !node
.parentNode
) && cbi_d_check(entry
.deps
)) {
349 parent
.appendChild(entry
.node
);
351 next
.parentNode
.insertBefore(entry
.node
, next
);
355 cbi_c
[entry
.parent
]++;
359 if (entry
&& entry
.parent
) {
361 cbi_tag_last(parent
);
369 function cbi_bind(obj
, type
, callback
, mode
) {
370 if (!obj
.addEventListener
) {
371 obj
.attachEvent('on' + type
,
373 var e
= window
.event
;
375 if (!e
.target
&& e
.srcElement
)
376 e
.target
= e
.srcElement
;
378 return !!callback(e
);
382 obj
.addEventListener(type
, callback
, !!mode
);
387 function cbi_combobox(id
, values
, def
, man
) {
388 var selid
= "cbi.combobox." + id
;
389 if (document
.getElementById(selid
)) {
393 var obj
= document
.getElementById(id
)
394 var sel
= document
.createElement("select");
396 sel
.className
= 'cbi-input-select';
398 if (obj
.nextSibling
) {
399 obj
.parentNode
.insertBefore(sel
, obj
.nextSibling
);
401 obj
.parentNode
.appendChild(sel
);
404 var dt
= obj
.getAttribute('cbi_datatype');
405 var op
= obj
.getAttribute('cbi_optional');
408 cbi_validate_field(sel
, op
== 'true', dt
);
410 if (!values
[obj
.value
]) {
411 if (obj
.value
== "") {
412 var optdef
= document
.createElement("option");
414 optdef
.appendChild(document
.createTextNode(def
));
415 sel
.appendChild(optdef
);
417 var opt
= document
.createElement("option");
418 opt
.value
= obj
.value
;
419 opt
.selected
= "selected";
420 opt
.appendChild(document
.createTextNode(obj
.value
));
421 sel
.appendChild(opt
);
425 for (var i
in values
) {
426 var opt
= document
.createElement("option");
429 if (obj
.value
== i
) {
430 opt
.selected
= "selected";
433 opt
.appendChild(document
.createTextNode(values
[i
]));
434 sel
.appendChild(opt
);
437 var optman
= document
.createElement("option");
439 optman
.appendChild(document
.createTextNode(man
));
440 sel
.appendChild(optman
);
442 obj
.style
.display
= "none";
444 cbi_bind(sel
, "change", function() {
445 if (sel
.selectedIndex
== sel
.options
.length
- 1) {
446 obj
.style
.display
= "inline";
447 sel
.parentNode
.removeChild(sel
);
450 obj
.value
= sel
.options
[sel
.selectedIndex
].value
;
461 function cbi_combobox_init(id
, values
, def
, man
) {
462 var obj
= document
.getElementById(id
);
463 cbi_bind(obj
, "blur", function() {
464 cbi_combobox(id
, values
, def
, man
)
466 cbi_combobox(id
, values
, def
, man
);
469 function cbi_filebrowser(id
, url
, defpath
) {
470 var field
= document
.getElementById(id
);
471 var browser
= window
.open(
472 url
+ ( field
.value
|| defpath
|| '' ) + '?field=' + id
,
473 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
479 function cbi_browser_init(id
, respath
, url
, defpath
)
481 function cbi_browser_btnclick(e
) {
482 cbi_filebrowser(id
, url
, defpath
);
486 var field
= document
.getElementById(id
);
488 var btn
= document
.createElement('img');
489 btn
.className
= 'cbi-image-button';
490 btn
.src
= respath
+ '/cbi/folder.gif';
491 field
.parentNode
.insertBefore(btn
, field
.nextSibling
);
493 cbi_bind(btn
, 'click', cbi_browser_btnclick
);
496 function cbi_dynlist_init(name
, respath
)
498 function cbi_dynlist_renumber(e
)
500 /* in a perfect world, we could just getElementsByName() - but not if
501 * MSIE is involved... */
502 var inputs
= [ ]; // = document.getElementsByName(name);
503 for (var i
= 0; i
< e
.parentNode
.childNodes
.length
; i
++)
504 if (e
.parentNode
.childNodes
[i
].name
== name
)
505 inputs
.push(e
.parentNode
.childNodes
[i
]);
507 for (var i
= 0; i
< inputs
.length
; i
++)
509 inputs
[i
].id
= name
+ '.' + (i
+ 1);
510 inputs
[i
].nextSibling
.src
= respath
+ (
511 (i
+1) < inputs
.length
? '/cbi/remove.gif' : '/cbi/add.gif'
518 function cbi_dynlist_keypress(ev
)
520 ev
= ev
? ev
: window
.event
;
522 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
524 if (se
.nodeType
== 3)
529 /* backspace, delete */
532 if (se
.value
.length
== 0)
534 if (ev
.preventDefault
)
542 /* enter, arrow up, arrow down */
546 if (ev
.preventDefault
)
555 function cbi_dynlist_keydown(ev
)
557 ev
= ev
? ev
: window
.event
;
559 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
561 if (se
.nodeType
== 3)
564 var prev
= se
.previousSibling
;
565 while (prev
&& prev
.name
!= name
)
566 prev
= prev
.previousSibling
;
568 var next
= se
.nextSibling
;
569 while (next
&& next
.name
!= name
)
570 next
= next
.nextSibling
;
574 /* backspace, delete */
577 var jump
= (ev
.keyCode
== 8)
578 ? (prev
|| next
) : (next
|| prev
);
580 if (se
.value
.length
== 0 && jump
)
582 se
.parentNode
.removeChild(se
.nextSibling
.nextSibling
);
583 se
.parentNode
.removeChild(se
.nextSibling
);
584 se
.parentNode
.removeChild(se
);
586 cbi_dynlist_renumber(jump
);
588 if (ev
.preventDefault
)
591 /* IE Quirk, needs double focus somehow */
601 var n
= document
.createElement('input');
605 var b
= document
.createElement('img');
607 cbi_bind(n
, 'keydown', cbi_dynlist_keydown
);
608 cbi_bind(n
, 'keypress', cbi_dynlist_keypress
);
609 cbi_bind(b
, 'click', cbi_dynlist_btnclick
);
613 se
.parentNode
.insertBefore(n
, next
);
614 se
.parentNode
.insertBefore(b
, next
);
615 se
.parentNode
.insertBefore(document
.createElement('br'), next
);
619 se
.parentNode
.appendChild(n
);
620 se
.parentNode
.appendChild(b
);
621 se
.parentNode
.appendChild(document
.createElement('br'));
624 var dt
= se
.getAttribute('cbi_datatype');
625 var op
= se
.getAttribute('cbi_optional') == 'true';
628 cbi_validate_field(n
, op
, dt
);
630 cbi_dynlist_renumber(n
);
651 function cbi_dynlist_btnclick(ev
)
653 ev
= ev
? ev
: window
.event
;
655 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
657 if (se
.src
.indexOf('remove') > -1)
659 se
.previousSibling
.value
= '';
661 cbi_dynlist_keydown({
662 target
: se
.previousSibling
,
668 cbi_dynlist_keydown({
669 target
: se
.previousSibling
,
677 var inputs
= document
.getElementsByName(name
);
678 for( var i
= 0; i
< inputs
.length
; i
++ )
680 var btn
= document
.createElement('img');
681 btn
.className
= 'cbi-image-button';
682 btn
.src
= respath
+ (
683 (i
+1) < inputs
.length
? '/cbi/remove.gif' : '/cbi/add.gif'
686 inputs
[i
].parentNode
.insertBefore(btn
, inputs
[i
].nextSibling
);
688 cbi_bind(inputs
[i
], 'keydown', cbi_dynlist_keydown
);
689 cbi_bind(inputs
[i
], 'keypress', cbi_dynlist_keypress
);
690 cbi_bind(btn
, 'click', cbi_dynlist_btnclick
);
694 //Hijacks the CBI form to send via XHR (requires Prototype)
695 function cbi_hijack_forms(layer
, win
, fail
, load
) {
696 var forms
= layer
.getElementsByTagName('form');
697 for (var i
=0; i
<forms
.length
; i
++) {
698 $(forms
[i
]).observe('submit', function(event
) {
699 // Prevent the form from also submitting the regular way
703 event
.element().request({
716 function cbi_t_add(section
, tab
) {
717 var t
= document
.getElementById('tab.' + section
+ '.' + tab
);
718 var c
= document
.getElementById('container.' + section
+ '.' + tab
);
721 cbi_t
[section
] = (cbi_t
[section
] || [ ]);
722 cbi_t
[section
][tab
] = { 'tab': t
, 'container': c
, 'cid': c
.id
};
726 function cbi_t_switch(section
, tab
) {
727 if( cbi_t
[section
] && cbi_t
[section
][tab
] ) {
728 var o
= cbi_t
[section
][tab
];
729 var h
= document
.getElementById('tab.' + section
);
730 for( var tid
in cbi_t
[section
] ) {
731 var o2
= cbi_t
[section
][tid
];
732 if( o
.tab
.id
!= o2
.tab
.id
) {
733 o2
.tab
.className
= o2
.tab
.className
.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
734 o2
.container
.style
.display
= 'none';
738 o2
.tab
.className
= o2
.tab
.className
.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
739 o2
.container
.style
.display
= 'block';
746 function cbi_t_update() {
750 for( var sid
in cbi_t
)
751 for( var tid
in cbi_t
[sid
] )
753 if( cbi_c
[cbi_t
[sid
][tid
].cid
] == 0 ) {
754 cbi_t
[sid
][tid
].tab
.style
.display
= 'none';
756 else if( cbi_t
[sid
][tid
].tab
&& cbi_t
[sid
][tid
].tab
.style
.display
== 'none' ) {
757 cbi_t
[sid
][tid
].tab
.style
.display
= '';
759 var t
= cbi_t
[sid
][tid
].tab
;
760 t
.className
+= ' cbi-tab-highlighted';
764 cbi_tag_last(cbi_t
[sid
][tid
].container
);
768 if( hl_tabs
.length
> 0 )
769 window
.setTimeout(function() {
770 for( var i
= 0; i
< hl_tabs
.length
; i
++ )
771 hl_tabs
[i
].className
= hl_tabs
[i
].className
.replace(/ cbi
-tab
-highlighted
/g
, '');
778 function cbi_validate_form(form
, errmsg
)
780 /* if triggered by a section removal or addition, don't validate */
781 if( form
.cbi_state
== 'add-section' || form
.cbi_state
== 'del-section' )
784 if( form
.cbi_validators
)
786 for( var i
= 0; i
< form
.cbi_validators
.length
; i
++ )
788 var validator
= form
.cbi_validators
[i
];
789 if( !validator() && errmsg
)
800 function cbi_validate_reset(form
)
803 function() { cbi_validate_form(form
, null) }, 100
809 function cbi_validate_field(cbid
, optional
, type
)
811 var field
= (typeof cbid
== "string") ? document
.getElementById(cbid
) : cbid
;
814 if( type
.match(/^(\w+)\(([^\(\)]+)\)/) )
817 vargs
= RegExp
.$2.split(/\s*,\s*/);
820 var vldcb
= cbi_validators
[type
];
824 var validator = function()
829 field
.className
= field
.className
.replace(/ cbi
-input
-invalid
/g
, '');
832 var value
= (field
.options
&& field
.options
.selectedIndex
> -1)
833 ? field
.options
[field
.options
.selectedIndex
].value
: field
.value
;
835 if( !(((value
.length
== 0) && optional
) || vldcb(value
, vargs
)) )
838 field
.className
+= ' cbi-input-invalid';
846 if( ! field
.form
.cbi_validators
)
847 field
.form
.cbi_validators
= [ ];
849 field
.form
.cbi_validators
.push(validator
);
851 cbi_bind(field
, "blur", validator
);
852 cbi_bind(field
, "keyup", validator
);
854 if (field
.nodeName
== 'SELECT')
856 cbi_bind(field
, "change", validator
);
857 cbi_bind(field
, "click", validator
);
860 field
.setAttribute("cbi_validate", validator
);
861 field
.setAttribute("cbi_datatype", type
);
862 field
.setAttribute("cbi_optional", (!!optional
).toString());
866 var fcbox
= document
.getElementById('cbi.combobox.' + field
.id
);
868 cbi_validate_field(fcbox
, optional
, type
);
872 function cbi_row_swap(elem
, up
, store
)
874 var tr
= elem
.parentNode
;
875 while (tr
&& tr
.nodeName
.toLowerCase() != 'tr')
881 var table
= tr
.parentNode
;
882 while (table
&& table
.nodeName
.toLowerCase() != 'table')
883 table
= table
.parentNode
;
889 var e
= up
? table
.rows
.length
: table
.rows
.length
- 1;
891 for (var idx
= s
; idx
< e
; idx
++)
893 if (table
.rows
[idx
] == tr
)
896 tr
.parentNode
.insertBefore(table
.rows
[idx
], table
.rows
[idx
-1]);
898 tr
.parentNode
.insertBefore(table
.rows
[idx
+1], table
.rows
[idx
]);
905 for (idx
= 2; idx
< table
.rows
.length
; idx
++)
907 table
.rows
[idx
].className
= table
.rows
[idx
].className
.replace(
908 /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx
% 2))
911 if (table
.rows
[idx
].id
&& table
.rows
[idx
].id
.match(/-([^\-]+)$/) )
915 var input
= document
.getElementById(store
);
917 input
.value
= ids
.join(' ');
922 function cbi_tag_last(container
)
926 for (var i
= 0; i
< container
.childNodes
.length
; i
++)
928 var c
= container
.childNodes
[i
];
929 if (c
.nodeType
== 1 && c
.nodeName
.toLowerCase() == 'div')
931 c
.className
= c
.className
.replace(/ cbi
-value
-last
$/, '');
938 last
.className
+= ' cbi-value-last';
942 if( ! String
.serialize
)
943 String
.serialize = function(o
)
959 for( var i
= 0; i
< o
.length
; i
++ )
960 s
+= (s
? ', ' : '') + String
.serialize(o
[i
]);
962 return '[ ' + s
+ ' ]';
971 s
+= (s
? ', ' : '') + k
+ ': ' + String
.serialize(o
[k
]);
973 return '{ ' + s
+ ' }';
980 if( o
.match(/[^a-zA-Z0-9_,.: -]/) )
981 return 'decodeURIComponent("' + encodeURIComponent(o
) + '")';
985 return '"' + o
+ '"';
995 if( ! String
.format
)
996 String
.format = function()
998 if (!arguments
|| arguments
.length
< 1 || !RegExp
)
1001 var html_esc
= [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1002 var quot_esc = [/"/g
, '"', /'/g, '''];
1004 function esc(s, r) {
1005 for( var i = 0; i < r.length; i += 2 )
1006 s = s.replace(r[i], r[i+1]);
1010 var str = arguments[0];
1012 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d
+)?(\.\d
+)?(%|b
|c
|d
|u
|f
|o
|s
|x
|X
|q
|h
|j
|t
|m
))/;
1013 var a
= b
= [], numSubstitutions
= 0, numMatches
= 0;
1015 while( a
= re
.exec(str
) )
1018 var leftpart
= a
[2], pPad
= a
[3], pJustify
= a
[4], pMinLength
= a
[5];
1019 var pPrecision
= a
[6], pType
= a
[7];
1029 if (numSubstitutions
++ < arguments
.length
)
1031 var param
= arguments
[numSubstitutions
];
1034 if (pPad
&& pPad
.substr(0,1) == "'")
1035 pad
= leftpart
.substr(1,1);
1039 var justifyRight
= true;
1040 if (pJustify
&& pJustify
=== "-")
1041 justifyRight
= false;
1045 minLength
= parseInt(pMinLength
);
1048 if (pPrecision
&& pType
== 'f')
1049 precision
= parseInt(pPrecision
.substring(1));
1056 subst
= (parseInt(param
) || 0).toString(2);
1060 subst
= String
.fromCharCode(parseInt(param
) || 0);
1064 subst
= (parseInt(param
) || 0);
1068 subst
= Math
.abs(parseInt(param
) || 0);
1072 subst
= (precision
> -1)
1073 ? ((parseFloat(param
) || 0.0)).toFixed(precision
)
1074 : (parseFloat(param
) || 0.0);
1078 subst
= (parseInt(param
) || 0).toString(8);
1086 subst
= ('' + (parseInt(param
) || 0).toString(16)).toLowerCase();
1090 subst
= ('' + (parseInt(param
) || 0).toString(16)).toUpperCase();
1094 subst
= esc(param
, html_esc
);
1098 subst
= esc(param
, quot_esc
);
1102 subst
= String
.serialize(param
);
1109 var ts
= (param
|| 0);
1112 tm
= Math
.floor(ts
/ 60);
1117 th
= Math
.floor(tm
/ 60);
1122 td
= Math
.floor(th
/ 24);
1127 ? String
.format('%dd %dh %dm %ds', td
, th
, tm
, ts
)
1128 : String
.format('%dh %dm %ds', th
, tm
, ts
);
1133 var mf
= pMinLength
? parseInt(pMinLength
) : 1000;
1134 var pr
= pPrecision
? Math
.floor(10*parseFloat('0'+pPrecision
)) : 2;
1137 var val
= parseFloat(param
|| 0);
1138 var units
= [ '', 'K', 'M', 'G', 'T', 'P', 'E' ];
1140 for (i
= 0; (i
< units
.length
) && (val
> mf
); i
++)
1143 subst
= val
.toFixed(pr
) + ' ' + units
[i
];
1149 out
+= leftpart
+ subst
;
1150 str
= str
.substr(m
.length
);