2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008-2012 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
= {
22 return (this.match(/^-?[0-9]+$/) != null);
25 'uinteger': function()
27 return (cbi_validators
.integer
.apply(this) && (this >= 0));
32 return !isNaN(parseFloat(this));
37 return (cbi_validators
['float'].apply(this) && (this >= 0));
42 return cbi_validators
.ip4addr
.apply(this) ||
43 cbi_validators
.ip6addr
.apply(this);
48 if (this.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(\/(\S+))?$/))
50 return (RegExp
.$1 >= 0) && (RegExp
.$1 <= 255) &&
51 (RegExp
.$2 >= 0) && (RegExp
.$2 <= 255) &&
52 (RegExp
.$3 >= 0) && (RegExp
.$3 <= 255) &&
53 (RegExp
.$4 >= 0) && (RegExp
.$4 <= 255) &&
54 ((RegExp
.$6.indexOf('.') < 0)
55 ? ((RegExp
.$6 >= 0) && (RegExp
.$6 <= 32))
56 : (cbi_validators
.ip4addr
.apply(RegExp
.$6)))
65 if( this.match(/^([a-fA-F0-9:.]+)(\/(\d+))?$/) )
67 if( !RegExp
.$2 || ((RegExp
.$3 >= 0) && (RegExp
.$3 <= 128)) )
76 if( addr
.indexOf('.') > 0 )
78 var off
= addr
.lastIndexOf(':');
80 if( !(off
&& cbi_validators
.ip4addr
.apply(addr
.substr(off
+1))) )
83 addr
= addr
.substr(0, off
) + ':0:0';
86 if( addr
.indexOf('::') >= 0 )
91 for( var i
= 1; i
< (addr
.length
-1); i
++ )
92 if( addr
.charAt(i
) == ':' )
98 for( var i
= 0; i
< (7 - colons
); i
++ )
101 if (addr
.match(/^(.*?)::(.*?)$/))
102 addr
= (RegExp
.$1 ? RegExp
.$1 + ':' : '') + fill
+
103 (RegExp
.$2 ? ':' + RegExp
.$2 : '');
106 return (addr
.match(/^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/) != null);
115 return cbi_validators
.integer
.apply(this) &&
116 (this >= 0) && (this <= 65535);
119 'portrange': function()
121 if (this.match(/^(\d+)-(\d+)$/))
126 return cbi_validators
.port
.apply(p1
) &&
127 cbi_validators
.port
.apply(p2
) &&
128 (parseInt(p1
) <= parseInt(p2
))
133 return cbi_validators
.port
.apply(this);
137 'macaddr': function()
139 return (this.match(/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/) != null);
144 return cbi_validators
.hostname
.apply(this) ||
145 cbi_validators
.ipaddr
.apply(this);
148 'hostname': function()
150 if (this.length
<= 253)
151 return (this.match(/^[a-zA-Z0-9]+$/) != null ||
152 (this.match(/^[a-zA-Z0-9_][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$/) &&
153 this.match(/[^0-9.]/)));
158 'network': function()
160 return cbi_validators
.uciname
.apply(this) ||
161 cbi_validators
.host
.apply(this);
169 return (v
.match(/^[a-fA-F0-9]{64}$/) != null);
171 return (v
.length
>= 8) && (v
.length
<= 63);
178 if ( v
.substr(0,2) == 's:' )
181 if( (v
.length
== 10) || (v
.length
== 26) )
182 return (v
.match(/^[a-fA-F0-9]{10,26}$/) != null);
184 return (v
.length
== 5) || (v
.length
== 13);
187 'uciname': function()
189 return (this.match(/^[a-zA-Z0-9_]+$/) != null);
192 'range': function(min
, max
)
194 var val
= parseFloat(this);
195 if (!isNaN(min
) && !isNaN(max
) && !isNaN(val
))
196 return ((val
>= min
) && (val
<= max
));
203 var val
= parseFloat(this);
204 if (!isNaN(min
) && !isNaN(val
))
212 var val
= parseFloat(this);
213 if (!isNaN(max
) && !isNaN(val
))
219 'rangelength': function(min
, max
)
222 if (!isNaN(min
) && !isNaN(max
))
223 return ((val
.length
>= min
) && (val
.length
<= max
));
228 'minlength': function(min
)
232 return (val
.length
>= min
);
237 'maxlength': function(max
)
241 return (val
.length
<= max
);
248 for (var i
= 0; i
< arguments
.length
; i
+= 2)
250 if (typeof arguments
[i
] != 'function')
252 if (arguments
[i
] == this)
256 else if (arguments
[i
].apply(this, arguments
[i
+1]))
266 for (var i
= 0; i
< arguments
.length
; i
+= 2)
268 if (typeof arguments
[i
] != 'function')
270 if (arguments
[i
] != this)
274 else if (!arguments
[i
].apply(this, arguments
[i
+1]))
284 return cbi_validators
.or
.apply(
285 this.replace(/^[ \t]*![ \t]*/, ''), arguments
);
288 'list': function(subvalidator
, subargs
)
290 if (typeof subvalidator
!= 'function')
293 var tokens
= this.match(/[^ \t]+/g);
294 for (var i
= 0; i
< tokens
.length
; i
++)
295 if (!subvalidator
.apply(tokens
[i
], subargs
))
300 'phonedigit': function()
302 return (this.match(/^[0-9\*#]+$/) != null);
307 function cbi_d_add(field
, dep
, next
) {
308 var obj
= document
.getElementById(field
);
311 for (var i
=0; i
<cbi_d
.length
; i
++) {
312 if (cbi_d
[i
].id
== field
) {
321 "parent": obj
.parentNode
.id
,
325 cbi_d
.unshift(entry
);
331 function cbi_d_checkvalue(target
, ref
) {
332 var t
= document
.getElementById(target
);
336 var tl
= document
.getElementsByName(target
);
338 if( tl
.length
> 0 && tl
[0].type
== 'radio' )
339 for( var i
= 0; i
< tl
.length
; i
++ )
340 if( tl
[i
].checked
) {
345 value
= value
? value
: "";
346 } else if (!t
.value
) {
351 if (t
.type
== "checkbox") {
352 value
= t
.checked
? value
: "";
356 return (value
== ref
)
359 function cbi_d_check(deps
) {
362 for (var i
=0; i
<deps
.length
; i
++) {
365 for (var j
in deps
[i
]) {
366 if (j
== "!reverse") {
368 } else if (j
== "!default") {
372 istat
= (istat
&& cbi_d_checkvalue(j
, deps
[i
][j
]))
382 function cbi_d_update() {
384 for (var i
=0; i
<cbi_d
.length
; i
++) {
385 var entry
= cbi_d
[i
];
386 var next
= document
.getElementById(entry
.next
)
387 var node
= document
.getElementById(entry
.id
)
388 var parent
= document
.getElementById(entry
.parent
)
390 if (node
&& node
.parentNode
&& !cbi_d_check(entry
.deps
)) {
391 node
.parentNode
.removeChild(node
);
394 cbi_c
[entry
.parent
]--;
395 } else if ((!node
|| !node
.parentNode
) && cbi_d_check(entry
.deps
)) {
397 parent
.appendChild(entry
.node
);
399 next
.parentNode
.insertBefore(entry
.node
, next
);
403 cbi_c
[entry
.parent
]++;
407 if (entry
&& entry
.parent
) {
409 cbi_tag_last(parent
);
417 function cbi_bind(obj
, type
, callback
, mode
) {
418 if (!obj
.addEventListener
) {
419 obj
.attachEvent('on' + type
,
421 var e
= window
.event
;
423 if (!e
.target
&& e
.srcElement
)
424 e
.target
= e
.srcElement
;
426 return !!callback(e
);
430 obj
.addEventListener(type
, callback
, !!mode
);
435 function cbi_combobox(id
, values
, def
, man
) {
436 var selid
= "cbi.combobox." + id
;
437 if (document
.getElementById(selid
)) {
441 var obj
= document
.getElementById(id
)
442 var sel
= document
.createElement("select");
444 sel
.className
= obj
.className
.replace(/cbi-input-text/, 'cbi-input-select');
446 if (obj
.nextSibling
) {
447 obj
.parentNode
.insertBefore(sel
, obj
.nextSibling
);
449 obj
.parentNode
.appendChild(sel
);
452 var dt
= obj
.getAttribute('cbi_datatype');
453 var op
= obj
.getAttribute('cbi_optional');
456 cbi_validate_field(sel
, op
== 'true', dt
);
458 if (!values
[obj
.value
]) {
459 if (obj
.value
== "") {
460 var optdef
= document
.createElement("option");
462 optdef
.appendChild(document
.createTextNode(def
));
463 sel
.appendChild(optdef
);
465 var opt
= document
.createElement("option");
466 opt
.value
= obj
.value
;
467 opt
.selected
= "selected";
468 opt
.appendChild(document
.createTextNode(obj
.value
));
469 sel
.appendChild(opt
);
473 for (var i
in values
) {
474 var opt
= document
.createElement("option");
477 if (obj
.value
== i
) {
478 opt
.selected
= "selected";
481 opt
.appendChild(document
.createTextNode(values
[i
]));
482 sel
.appendChild(opt
);
485 var optman
= document
.createElement("option");
487 optman
.appendChild(document
.createTextNode(man
));
488 sel
.appendChild(optman
);
490 obj
.style
.display
= "none";
492 cbi_bind(sel
, "change", function() {
493 if (sel
.selectedIndex
== sel
.options
.length
- 1) {
494 obj
.style
.display
= "inline";
495 sel
.parentNode
.removeChild(sel
);
498 obj
.value
= sel
.options
[sel
.selectedIndex
].value
;
508 // Retrigger validation in select
513 function cbi_combobox_init(id
, values
, def
, man
) {
514 var obj
= document
.getElementById(id
);
515 cbi_bind(obj
, "blur", function() {
516 cbi_combobox(id
, values
, def
, man
)
518 cbi_combobox(id
, values
, def
, man
);
521 function cbi_filebrowser(id
, url
, defpath
) {
522 var field
= document
.getElementById(id
);
523 var browser
= window
.open(
524 url
+ ( field
.value
|| defpath
|| '' ) + '?field=' + id
,
525 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
531 function cbi_browser_init(id
, respath
, url
, defpath
)
533 function cbi_browser_btnclick(e
) {
534 cbi_filebrowser(id
, url
, defpath
);
538 var field
= document
.getElementById(id
);
540 var btn
= document
.createElement('img');
541 btn
.className
= 'cbi-image-button';
542 btn
.src
= respath
+ '/cbi/folder.gif';
543 field
.parentNode
.insertBefore(btn
, field
.nextSibling
);
545 cbi_bind(btn
, 'click', cbi_browser_btnclick
);
548 function cbi_dynlist_init(name
, respath
, datatype
, optional
, choices
)
550 var input0
= document
.getElementsByName(name
)[0];
551 var prefix
= input0
.name
;
552 var parent
= input0
.parentNode
;
553 var holder
= input0
.placeholder
;
557 function cbi_dynlist_redraw(focus
, add
, del
)
561 while (parent
.firstChild
)
563 var n
= parent
.firstChild
;
564 var i
= parseInt(n
.index
);
568 if (n
.nodeName
.toLowerCase() == 'input')
569 values
.push(n
.value
|| '');
570 else if (n
.nodeName
.toLowerCase() == 'select')
571 values
[values
.length
-1] = n
.options
[n
.selectedIndex
].value
;
574 parent
.removeChild(n
);
580 values
.splice(focus
, 0, '');
582 else if (values
.length
== 0)
588 for (var i
= 0; i
< values
.length
; i
++)
590 var t
= document
.createElement('input');
591 t
.id
= prefix
+ '.' + (i
+1);
596 t
.className
= 'cbi-input-text';
598 if (i
== 0 && holder
)
600 t
.placeholder
= holder
;
603 var b
= document
.createElement('img');
604 b
.src
= respath
+ ((i
+1) < values
.length
? '/cbi/remove.gif' : '/cbi/add.gif');
605 b
.className
= 'cbi-image-button';
607 parent
.appendChild(t
);
608 parent
.appendChild(b
);
609 parent
.appendChild(document
.createElement('br'));
613 cbi_validate_field(t
.id
, ((i
+1) == values
.length
) || optional
, datatype
);
618 cbi_combobox_init(t
.id
, choices
[0], '', choices
[1]);
619 t
.nextSibling
.index
= i
;
621 cbi_bind(t
.nextSibling
, 'keydown', cbi_dynlist_keydown
);
622 cbi_bind(t
.nextSibling
, 'keypress', cbi_dynlist_keypress
);
624 if (i
== focus
|| -i
== focus
)
625 t
.nextSibling
.focus();
629 cbi_bind(t
, 'keydown', cbi_dynlist_keydown
);
630 cbi_bind(t
, 'keypress', cbi_dynlist_keypress
);
636 else if (-i
== focus
)
640 /* force cursor to end */
647 cbi_bind(b
, 'click', cbi_dynlist_btnclick
);
651 function cbi_dynlist_keypress(ev
)
653 ev
= ev
? ev
: window
.event
;
655 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
657 if (se
.nodeType
== 3)
662 /* backspace, delete */
665 if (se
.value
.length
== 0)
667 if (ev
.preventDefault
)
675 /* enter, arrow up, arrow down */
679 if (ev
.preventDefault
)
688 function cbi_dynlist_keydown(ev
)
690 ev
= ev
? ev
: window
.event
;
692 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
694 if (se
.nodeType
== 3)
697 var prev
= se
.previousSibling
;
698 while (prev
&& prev
.name
!= name
)
699 prev
= prev
.previousSibling
;
701 var next
= se
.nextSibling
;
702 while (next
&& next
.name
!= name
)
703 next
= next
.nextSibling
;
705 /* advance one further in combobox case */
706 if (next
&& next
.nextSibling
.name
== name
)
707 next
= next
.nextSibling
;
711 /* backspace, delete */
714 var del
= (se
.nodeName
.toLowerCase() == 'select')
715 ? true : (se
.value
.length
== 0);
719 if (ev
.preventDefault
)
722 var focus
= se
.index
;
726 cbi_dynlist_redraw(focus
, -1, se
.index
);
735 cbi_dynlist_redraw(-1, se
.index
, -1);
756 function cbi_dynlist_btnclick(ev
)
758 ev
= ev
? ev
: window
.event
;
760 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
762 if (se
.src
.indexOf('remove') > -1)
764 se
.previousSibling
.value
= '';
766 cbi_dynlist_keydown({
767 target
: se
.previousSibling
,
773 cbi_dynlist_keydown({
774 target
: se
.previousSibling
,
782 cbi_dynlist_redraw(NaN
, -1, -1);
785 //Hijacks the CBI form to send via XHR (requires Prototype)
786 function cbi_hijack_forms(layer
, win
, fail
, load
) {
787 var forms
= layer
.getElementsByTagName('form');
788 for (var i
=0; i
<forms
.length
; i
++) {
789 $(forms
[i
]).observe('submit', function(event
) {
790 // Prevent the form from also submitting the regular way
794 event
.element().request({
807 function cbi_t_add(section
, tab
) {
808 var t
= document
.getElementById('tab.' + section
+ '.' + tab
);
809 var c
= document
.getElementById('container.' + section
+ '.' + tab
);
812 cbi_t
[section
] = (cbi_t
[section
] || [ ]);
813 cbi_t
[section
][tab
] = { 'tab': t
, 'container': c
, 'cid': c
.id
};
817 function cbi_t_switch(section
, tab
) {
818 if( cbi_t
[section
] && cbi_t
[section
][tab
] ) {
819 var o
= cbi_t
[section
][tab
];
820 var h
= document
.getElementById('tab.' + section
);
821 for( var tid
in cbi_t
[section
] ) {
822 var o2
= cbi_t
[section
][tid
];
823 if( o
.tab
.id
!= o2
.tab
.id
) {
824 o2
.tab
.className
= o2
.tab
.className
.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
825 o2
.container
.style
.display
= 'none';
829 o2
.tab
.className
= o2
.tab
.className
.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
830 o2
.container
.style
.display
= 'block';
837 function cbi_t_update() {
841 for( var sid
in cbi_t
)
842 for( var tid
in cbi_t
[sid
] )
844 if( cbi_c
[cbi_t
[sid
][tid
].cid
] == 0 ) {
845 cbi_t
[sid
][tid
].tab
.style
.display
= 'none';
847 else if( cbi_t
[sid
][tid
].tab
&& cbi_t
[sid
][tid
].tab
.style
.display
== 'none' ) {
848 cbi_t
[sid
][tid
].tab
.style
.display
= '';
850 var t
= cbi_t
[sid
][tid
].tab
;
851 t
.className
+= ' cbi-tab-highlighted';
855 cbi_tag_last(cbi_t
[sid
][tid
].container
);
859 if( hl_tabs
.length
> 0 )
860 window
.setTimeout(function() {
861 for( var i
= 0; i
< hl_tabs
.length
; i
++ )
862 hl_tabs
[i
].className
= hl_tabs
[i
].className
.replace(/ cbi
-tab
-highlighted
/g
, '');
869 function cbi_validate_form(form
, errmsg
)
871 /* if triggered by a section removal or addition, don't validate */
872 if( form
.cbi_state
== 'add-section' || form
.cbi_state
== 'del-section' )
875 if( form
.cbi_validators
)
877 for( var i
= 0; i
< form
.cbi_validators
.length
; i
++ )
879 var validator
= form
.cbi_validators
[i
];
880 if( !validator() && errmsg
)
891 function cbi_validate_reset(form
)
894 function() { cbi_validate_form(form
, null) }, 100
900 function cbi_validate_compile(code
)
909 for (var i
= 0; i
< code
.length
; i
++)
917 switch (code
.charCodeAt(i
))
929 var label
= code
.substring(pos
, i
);
930 label
= label
.replace(/\\(.)/g, '$1');
931 label
= label
.replace(/^[ \t]+/g, '');
932 label
= label
.replace(/[ \t]+$/g, '');
934 if (label
&& !isNaN(label
))
936 stack
.push(parseFloat(label
));
938 else if (label
.match(/^(['"]).*\1$/))
940 stack
.push(label
.replace(/^(['"])(.*)\1$/, '$2'));
942 else if (typeof cbi_validators
[label
] == 'function')
944 stack
.push(cbi_validators
[label
]);
949 throw "Syntax error, unhandled token '"+label
+"'";
954 depth
+= (code
.charCodeAt(i
) == 40);
960 if (typeof stack
[stack
.length
-2] != 'function')
961 throw "Syntax error, argument list follows non-function";
963 stack
[stack
.length
-1] =
964 arguments
.callee(code
.substring(pos
, i
));
975 function cbi_validate_field(cbid
, optional
, type
)
977 var field
= (typeof cbid
== "string") ? document
.getElementById(cbid
) : cbid
;
978 var vstack
; try { vstack
= cbi_validate_compile(type
); } catch(e
) { };
980 if (field
&& vstack
&& typeof vstack
[0] == "function")
982 var validator = function()
987 field
.className
= field
.className
.replace(/ cbi
-input
-invalid
/g
, '');
990 var value
= (field
.options
&& field
.options
.selectedIndex
> -1)
991 ? field
.options
[field
.options
.selectedIndex
].value
: field
.value
;
993 if (!(((value
.length
== 0) && optional
) || vstack
[0].apply(value
, vstack
[1])))
996 field
.className
+= ' cbi-input-invalid';
1004 if( ! field
.form
.cbi_validators
)
1005 field
.form
.cbi_validators
= [ ];
1007 field
.form
.cbi_validators
.push(validator
);
1009 cbi_bind(field
, "blur", validator
);
1010 cbi_bind(field
, "keyup", validator
);
1012 if (field
.nodeName
== 'SELECT')
1014 cbi_bind(field
, "change", validator
);
1015 cbi_bind(field
, "click", validator
);
1018 field
.setAttribute("cbi_validate", validator
);
1019 field
.setAttribute("cbi_datatype", type
);
1020 field
.setAttribute("cbi_optional", (!!optional
).toString());
1024 var fcbox
= document
.getElementById('cbi.combobox.' + field
.id
);
1026 cbi_validate_field(fcbox
, optional
, type
);
1030 function cbi_row_swap(elem
, up
, store
)
1032 var tr
= elem
.parentNode
;
1033 while (tr
&& tr
.nodeName
.toLowerCase() != 'tr')
1039 var table
= tr
.parentNode
;
1040 while (table
&& table
.nodeName
.toLowerCase() != 'table')
1041 table
= table
.parentNode
;
1047 var e
= up
? table
.rows
.length
: table
.rows
.length
- 1;
1049 for (var idx
= s
; idx
< e
; idx
++)
1051 if (table
.rows
[idx
] == tr
)
1054 tr
.parentNode
.insertBefore(table
.rows
[idx
], table
.rows
[idx
-1]);
1056 tr
.parentNode
.insertBefore(table
.rows
[idx
+1], table
.rows
[idx
]);
1063 for (idx
= 2; idx
< table
.rows
.length
; idx
++)
1065 table
.rows
[idx
].className
= table
.rows
[idx
].className
.replace(
1066 /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx
% 2))
1069 if (table
.rows
[idx
].id
&& table
.rows
[idx
].id
.match(/-([^\-]+)$/) )
1070 ids
.push(RegExp
.$1);
1073 var input
= document
.getElementById(store
);
1075 input
.value
= ids
.join(' ');
1080 function cbi_tag_last(container
)
1084 for (var i
= 0; i
< container
.childNodes
.length
; i
++)
1086 var c
= container
.childNodes
[i
];
1087 if (c
.nodeType
== 1 && c
.nodeName
.toLowerCase() == 'div')
1089 c
.className
= c
.className
.replace(/ cbi
-value
-last
$/, '');
1096 last
.className
+= ' cbi-value-last';
1100 String
.prototype.serialize = function()
1117 for( var i
= 0; i
< o
.length
; i
++ )
1118 s
+= (s
? ', ' : '') + String
.serialize(o
[i
]);
1120 return '[ ' + s
+ ' ]';
1129 s
+= (s
? ', ' : '') + k
+ ': ' + String
.serialize(o
[k
]);
1131 return '{ ' + s
+ ' }';
1138 if( o
.match(/[^a-zA-Z0-9_,.: -]/) )
1139 return 'decodeURIComponent("' + encodeURIComponent(o
) + '")';
1143 return '"' + o
+ '"';
1148 return o
.toString();
1152 String
.prototype.format = function()
1157 var html_esc
= [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1158 var quot_esc = [/"/g
, '"', /'/g, '''];
1160 function esc(s, r) {
1161 for( var i = 0; i < r.length; i += 2 )
1162 s = s.replace(r[i], r[i+1]);
1168 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d
+)?(\.\d
+)?(%|b
|c
|d
|u
|f
|o
|s
|x
|X
|q
|h
|j
|t
|m
))/;
1169 var a
= b
= [], numSubstitutions
= 0, numMatches
= 0;
1171 while( a
= re
.exec(str
) )
1174 var leftpart
= a
[2], pPad
= a
[3], pJustify
= a
[4], pMinLength
= a
[5];
1175 var pPrecision
= a
[6], pType
= a
[7];
1185 if (numSubstitutions
< arguments
.length
)
1187 var param
= arguments
[numSubstitutions
++];
1190 if (pPad
&& pPad
.substr(0,1) == "'")
1191 pad
= leftpart
.substr(1,1);
1195 var justifyRight
= true;
1196 if (pJustify
&& pJustify
=== "-")
1197 justifyRight
= false;
1201 minLength
= parseInt(pMinLength
);
1204 if (pPrecision
&& pType
== 'f')
1205 precision
= parseInt(pPrecision
.substring(1));
1212 subst
= (parseInt(param
) || 0).toString(2);
1216 subst
= String
.fromCharCode(parseInt(param
) || 0);
1220 subst
= (parseInt(param
) || 0);
1224 subst
= Math
.abs(parseInt(param
) || 0);
1228 subst
= (precision
> -1)
1229 ? ((parseFloat(param
) || 0.0)).toFixed(precision
)
1230 : (parseFloat(param
) || 0.0);
1234 subst
= (parseInt(param
) || 0).toString(8);
1242 subst
= ('' + (parseInt(param
) || 0).toString(16)).toLowerCase();
1246 subst
= ('' + (parseInt(param
) || 0).toString(16)).toUpperCase();
1250 subst
= esc(param
, html_esc
);
1254 subst
= esc(param
, quot_esc
);
1258 subst
= String
.serialize(param
);
1265 var ts
= (param
|| 0);
1268 tm
= Math
.floor(ts
/ 60);
1273 th
= Math
.floor(tm
/ 60);
1278 td
= Math
.floor(th
/ 24);
1283 ? String
.format('%dd %dh %dm %ds', td
, th
, tm
, ts
)
1284 : String
.format('%dh %dm %ds', th
, tm
, ts
);
1289 var mf
= pMinLength
? parseInt(pMinLength
) : 1000;
1290 var pr
= pPrecision
? Math
.floor(10*parseFloat('0'+pPrecision
)) : 2;
1293 var val
= parseFloat(param
|| 0);
1294 var units
= [ '', 'K', 'M', 'G', 'T', 'P', 'E' ];
1296 for (i
= 0; (i
< units
.length
) && (val
> mf
); i
++)
1299 subst
= val
.toFixed(pr
) + ' ' + units
[i
];
1305 out
+= leftpart
+ subst
;
1306 str
= str
.substr(m
.length
);
1312 String
.prototype.nobr = function()
1314 return this.replace(/[\s\n]+/g, ' ');
1317 String
.serialize = function()
1320 for (var i
= 1; i
< arguments
.length
; i
++)
1321 a
.push(arguments
[i
]);
1322 return ''.serialize
.apply(arguments
[0], a
);
1325 String
.format = function()
1328 for (var i
= 1; i
< arguments
.length
; i
++)
1329 a
.push(arguments
[i
]);
1330 return ''.format
.apply(arguments
[0], a
);
1333 String
.nobr = function()
1336 for (var i
= 1; i
< arguments
.length
; i
++)
1337 a
.push(arguments
[i
]);
1338 return ''.nobr
.apply(arguments
[0], a
);