2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008-2012 Jo-Philipp Wich <jow@openwrt.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
17 var cbi_validators = {
21 return (this.match(/^-?[0-9]+$/) != null);
24 'uinteger': function()
26 return (cbi_validators.integer.apply(this) && (this >= 0));
31 return !isNaN(parseFloat(this));
36 return (cbi_validators['float'].apply(this) && (this >= 0));
41 return cbi_validators.ip4addr.apply(this) ||
42 cbi_validators.ip6addr.apply(this);
47 if (this.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(\/(\S+))?$/))
49 return (RegExp.$1 >= 0) && (RegExp.$1 <= 255) &&
50 (RegExp.$2 >= 0) && (RegExp.$2 <= 255) &&
51 (RegExp.$3 >= 0) && (RegExp.$3 <= 255) &&
52 (RegExp.$4 >= 0) && (RegExp.$4 <= 255) &&
53 ((RegExp.$6.indexOf('.') < 0)
54 ? ((RegExp.$6 >= 0) && (RegExp.$6 <= 32))
55 : (cbi_validators.ip4addr.apply(RegExp.$6)))
64 if( this.match(/^([a-fA-F0-9:.]+)(\/(\d+))?$/) )
66 if( !RegExp.$2 || ((RegExp.$3 >= 0) && (RegExp.$3 <= 128)) )
75 if( addr.indexOf('.') > 0 )
77 var off = addr.lastIndexOf(':');
79 if( !(off && cbi_validators.ip4addr.apply(addr.substr(off+1))) )
82 addr = addr.substr(0, off) + ':0:0';
85 if( addr.indexOf('::') >= 0 )
90 for( var i = 1; i < (addr.length-1); i++ )
91 if( addr.charAt(i) == ':' )
97 for( var i = 0; i < (7 - colons); i++ )
100 if (addr.match(/^(.*?)::(.*?)$/))
101 addr = (RegExp.$1 ? RegExp.$1 + ':' : '') + fill +
102 (RegExp.$2 ? ':' + RegExp.$2 : '');
105 return (addr.match(/^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/) != null);
114 return cbi_validators.integer.apply(this) &&
115 (this >= 0) && (this <= 65535);
118 'portrange': function()
120 if (this.match(/^(\d+)-(\d+)$/))
125 return cbi_validators.port.apply(p1) &&
126 cbi_validators.port.apply(p2) &&
127 (parseInt(p1) <= parseInt(p2))
132 return cbi_validators.port.apply(this);
136 'macaddr': function()
138 return (this.match(/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/) != null);
141 'host': function(ipv4only)
143 return cbi_validators.hostname.apply(this) ||
144 ((ipv4only != 1) && cbi_validators.ipaddr.apply(this)) ||
145 ((ipv4only == 1) && cb_validators.ip4addr.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);
164 'hostport': function(ipv4only)
166 var hp = this.split(/:/);
169 return (cbi_validators.host.apply(hp[0], ipv4only) &&
170 cbi_validators.port.apply(hp[1]));
175 'ip4addrport': function()
177 var hp = this.split(/:/);
180 return (cbi_validators.ipaddr.apply(hp[0]) &&
181 cbi_validators.port.apply(hp[1]));
185 'ipaddrport': function(bracket)
187 if (this.match(/^([^\[\]:]+):([^:]+)$/)) {
190 return (cbi_validators.ip4addr.apply(addr) &&
191 cbi_validators.port.apply(port));
192 } else if ((bracket == 1) && (this.match(/^\[(.+)\]:([^:]+)$/))) {
195 return (cbi_validators.ip6addr.apply(addr) &&
196 cbi_validators.port.apply(port));
197 } else if ((bracket != 1) && (this.match(/^([^\[\]]+):([^:]+)$/))) {
200 return (cbi_validators.ip6addr.apply(addr) &&
201 cbi_validators.port.apply(port));
212 return (v.match(/^[a-fA-F0-9]{64}$/) != null);
214 return (v.length >= 8) && (v.length <= 63);
221 if ( v.substr(0,2) == 's:' )
224 if( (v.length == 10) || (v.length == 26) )
225 return (v.match(/^[a-fA-F0-9]{10,26}$/) != null);
227 return (v.length == 5) || (v.length == 13);
230 'uciname': function()
232 return (this.match(/^[a-zA-Z0-9_]+$/) != null);
235 'range': function(min, max)
237 var val = parseFloat(this);
238 if (!isNaN(min) && !isNaN(max) && !isNaN(val))
239 return ((val >= min) && (val <= max));
246 var val = parseFloat(this);
247 if (!isNaN(min) && !isNaN(val))
255 var val = parseFloat(this);
256 if (!isNaN(max) && !isNaN(val))
262 'rangelength': function(min, max)
265 if (!isNaN(min) && !isNaN(max))
266 return ((val.length >= min) && (val.length <= max));
271 'minlength': function(min)
275 return (val.length >= min);
280 'maxlength': function(max)
284 return (val.length <= max);
291 for (var i = 0; i < arguments.length; i += 2)
293 if (typeof arguments[i] != 'function')
295 if (arguments[i] == this)
299 else if (arguments[i].apply(this, arguments[i+1]))
309 for (var i = 0; i < arguments.length; i += 2)
311 if (typeof arguments[i] != 'function')
313 if (arguments[i] != this)
317 else if (!arguments[i].apply(this, arguments[i+1]))
327 return cbi_validators.or.apply(
328 this.replace(/^[ \t]*![ \t]*/, ''), arguments);
331 'list': function(subvalidator, subargs)
333 if (typeof subvalidator != 'function')
336 var tokens = this.match(/[^ \t]+/g);
337 for (var i = 0; i < tokens.length; i++)
338 if (!subvalidator.apply(tokens[i], subargs))
343 'phonedigit': function()
345 return (this.match(/^[0-9\*#!\.]+$/) != null);
347 'timehhmmss': function()
349 return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null);
351 'dateyyyymmdd': function()
356 if (this.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)) {
357 var year = RegExp.$1;
358 var month = RegExp.$2;
361 var days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30 , 31, 30, 31 ];
362 function is_leap_year(year) {
363 return ((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0);
365 function get_days_in_month(month, year) {
366 if ((month == 2) && is_leap_year(year)) {
369 return days_in_month[month];
372 /* Firewall rules in the past don't make sense */
376 if ((month <= 0) || (month > 12)) {
379 if ((day <= 0) || (day > get_days_in_month(month, year))) {
391 function cbi_d_add(field, dep, index) {
392 var obj = (typeof(field) === 'string') ? document.getElementById(field) : field;
395 for (var i=0; i<cbi_d.length; i++) {
396 if (cbi_d[i].id == obj.id) {
405 "parent": obj.parentNode.id,
409 cbi_d.unshift(entry);
415 function cbi_d_checkvalue(target, ref) {
416 var t = document.getElementById(target);
420 var tl = document.getElementsByName(target);
422 if( tl.length > 0 && (tl[0].type == 'radio' || tl[0].type == 'checkbox'))
423 for( var i = 0; i < tl.length; i++ )
424 if( tl[i].checked ) {
429 value = value ? value : "";
430 } else if (!t.value) {
435 if (t.type == "checkbox") {
436 value = t.checked ? value : "";
440 return (value == ref)
443 function cbi_d_check(deps) {
446 for (var i=0; i<deps.length; i++) {
449 for (var j in deps[i]) {
450 if (j == "!reverse") {
452 } else if (j == "!default") {
456 istat = (istat && cbi_d_checkvalue(j, deps[i][j]))
466 function cbi_d_update() {
468 for (var i=0; i<cbi_d.length; i++) {
469 var entry = cbi_d[i];
470 var node = document.getElementById(entry.id);
471 var parent = document.getElementById(entry.parent);
473 if (node && node.parentNode && !cbi_d_check(entry.deps)) {
474 node.parentNode.removeChild(node);
476 } else if ((!node || !node.parentNode) && cbi_d_check(entry.deps)) {
477 var next = undefined;
479 for (next = parent.firstChild; next; next = next.nextSibling) {
480 if (next.getAttribute && parseInt(next.getAttribute('data-index'), 10) > entry.index) {
486 parent.appendChild(entry.node);
488 parent.insertBefore(entry.node, next);
495 if (entry && entry.parent) {
497 cbi_tag_last(parent);
505 function cbi_init() {
506 var nodes = document.querySelectorAll('[data-depends]');
508 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
509 var index = parseInt(node.getAttribute('data-index'), 10);
510 var depends = JSON.parse(node.getAttribute('data-depends'));
511 if (!isNaN(index) && depends.length > 0) {
512 for (var alt = 0; alt < depends.length; alt++) {
513 cbi_d_add(node, depends[alt], index);
518 nodes = document.querySelectorAll('[data-change]');
520 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
521 var events = node.getAttribute('data-change').split(' ');
522 for (var j = 0, event; (event = events[j]) !== undefined; j++) {
523 cbi_bind(node, event, cbi_d_update);
530 function cbi_bind(obj, type, callback, mode) {
531 if (!obj.addEventListener) {
532 obj.attachEvent('on' + type,
534 var e = window.event;
536 if (!e.target && e.srcElement)
537 e.target = e.srcElement;
539 return !!callback(e);
543 obj.addEventListener(type, callback, !!mode);
548 function cbi_combobox(id, values, def, man) {
549 var selid = "cbi.combobox." + id;
550 if (document.getElementById(selid)) {
554 var obj = document.getElementById(id)
555 var sel = document.createElement("select");
557 sel.className = obj.className.replace(/cbi-input-text/, 'cbi-input-select');
559 if (obj.nextSibling) {
560 obj.parentNode.insertBefore(sel, obj.nextSibling);
562 obj.parentNode.appendChild(sel);
565 var dt = obj.getAttribute('cbi_datatype');
566 var op = obj.getAttribute('cbi_optional');
569 cbi_validate_field(sel, op == 'true', dt);
571 if (!values[obj.value]) {
572 if (obj.value == "") {
573 var optdef = document.createElement("option");
575 optdef.appendChild(document.createTextNode(def));
576 sel.appendChild(optdef);
578 var opt = document.createElement("option");
579 opt.value = obj.value;
580 opt.selected = "selected";
581 opt.appendChild(document.createTextNode(obj.value));
582 sel.appendChild(opt);
586 for (var i in values) {
587 var opt = document.createElement("option");
590 if (obj.value == i) {
591 opt.selected = "selected";
594 opt.appendChild(document.createTextNode(values[i]));
595 sel.appendChild(opt);
598 var optman = document.createElement("option");
600 optman.appendChild(document.createTextNode(man));
601 sel.appendChild(optman);
603 obj.style.display = "none";
605 cbi_bind(sel, "change", function() {
606 if (sel.selectedIndex == sel.options.length - 1) {
607 obj.style.display = "inline";
608 sel.parentNode.removeChild(sel);
611 obj.value = sel.options[sel.selectedIndex].value;
621 // Retrigger validation in select
626 function cbi_combobox_init(id, values, def, man) {
627 var obj = document.getElementById(id);
628 cbi_bind(obj, "blur", function() {
629 cbi_combobox(id, values, def, man)
631 cbi_combobox(id, values, def, man);
634 function cbi_filebrowser(id, url, defpath) {
635 var field = document.getElementById(id);
636 var browser = window.open(
637 url + ( field.value || defpath || '' ) + '?field=' + id,
638 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
644 function cbi_browser_init(id, respath, url, defpath)
646 function cbi_browser_btnclick(e) {
647 cbi_filebrowser(id, url, defpath);
651 var field = document.getElementById(id);
653 var btn = document.createElement('img');
654 btn.className = 'cbi-image-button';
655 btn.src = respath + '/cbi/folder.gif';
656 field.parentNode.insertBefore(btn, field.nextSibling);
658 cbi_bind(btn, 'click', cbi_browser_btnclick);
661 function cbi_dynlist_init(name, respath, datatype, optional, url, defpath, choices)
663 var input0 = document.getElementsByName(name)[0];
664 var prefix = input0.name;
665 var parent = input0.parentNode;
666 var holder = input0.placeholder;
670 function cbi_dynlist_redraw(focus, add, del)
674 while (parent.firstChild)
676 var n = parent.firstChild;
677 var i = parseInt(n.index);
681 if (n.nodeName.toLowerCase() == 'input')
682 values.push(n.value || '');
683 else if (n.nodeName.toLowerCase() == 'select')
684 values[values.length-1] = n.options[n.selectedIndex].value;
687 parent.removeChild(n);
693 values.splice(focus, 0, '');
695 else if (values.length == 0)
701 for (var i = 0; i < values.length; i++)
703 var t = document.createElement('input');
704 t.id = prefix + '.' + (i+1);
709 t.className = 'cbi-input-text';
711 if (i == 0 && holder)
713 t.placeholder = holder;
716 var b = document.createElement('img');
717 b.src = respath + ((i+1) < values.length ? '/cbi/remove.gif' : '/cbi/add.gif');
718 b.className = 'cbi-image-button';
720 parent.appendChild(t);
721 parent.appendChild(b);
722 if (datatype == 'file')
724 cbi_browser_init(t.id, respath, url, defpath);
727 parent.appendChild(document.createElement('br'));
731 cbi_validate_field(t.id, ((i+1) == values.length) || optional, datatype);
736 cbi_combobox_init(t.id, choices[0], '', choices[1]);
739 cbi_bind(b, 'keydown', cbi_dynlist_keydown);
740 cbi_bind(b, 'keypress', cbi_dynlist_keypress);
742 if (i == focus || -i == focus)
747 cbi_bind(t, 'keydown', cbi_dynlist_keydown);
748 cbi_bind(t, 'keypress', cbi_dynlist_keypress);
754 else if (-i == focus)
758 /* force cursor to end */
765 cbi_bind(b, 'click', cbi_dynlist_btnclick);
769 function cbi_dynlist_keypress(ev)
771 ev = ev ? ev : window.event;
773 var se = ev.target ? ev.target : ev.srcElement;
775 if (se.nodeType == 3)
780 /* backspace, delete */
783 if (se.value.length == 0)
785 if (ev.preventDefault)
793 /* enter, arrow up, arrow down */
797 if (ev.preventDefault)
806 function cbi_dynlist_keydown(ev)
808 ev = ev ? ev : window.event;
810 var se = ev.target ? ev.target : ev.srcElement;
812 if (se.nodeType == 3)
815 var prev = se.previousSibling;
816 while (prev && prev.name != name)
817 prev = prev.previousSibling;
819 var next = se.nextSibling;
820 while (next && next.name != name)
821 next = next.nextSibling;
823 /* advance one further in combobox case */
824 if (next && next.nextSibling.name == name)
825 next = next.nextSibling;
829 /* backspace, delete */
832 var del = (se.nodeName.toLowerCase() == 'select')
833 ? true : (se.value.length == 0);
837 if (ev.preventDefault)
840 var focus = se.index;
844 cbi_dynlist_redraw(focus, -1, se.index);
853 cbi_dynlist_redraw(-1, se.index, -1);
874 function cbi_dynlist_btnclick(ev)
876 ev = ev ? ev : window.event;
878 var se = ev.target ? ev.target : ev.srcElement;
879 var input = se.previousSibling;
880 while (input && input.name != name) {
881 input = input.previousSibling;
884 if (se.src.indexOf('remove') > -1)
888 cbi_dynlist_keydown({
895 cbi_dynlist_keydown({
904 cbi_dynlist_redraw(NaN, -1, -1);
908 function cbi_t_add(section, tab) {
909 var t = document.getElementById('tab.' + section + '.' + tab);
910 var c = document.getElementById('container.' + section + '.' + tab);
913 cbi_t[section] = (cbi_t[section] || [ ]);
914 cbi_t[section][tab] = { 'tab': t, 'container': c, 'cid': c.id };
918 function cbi_t_switch(section, tab) {
919 if( cbi_t[section] && cbi_t[section][tab] ) {
920 var o = cbi_t[section][tab];
921 var h = document.getElementById('tab.' + section);
922 for( var tid in cbi_t[section] ) {
923 var o2 = cbi_t[section][tid];
924 if( o.tab.id != o2.tab.id ) {
925 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
926 o2.container.style.display = 'none';
930 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
931 o2.container.style.display = 'block';
938 function cbi_t_update() {
942 for( var sid in cbi_t )
943 for( var tid in cbi_t[sid] )
945 var t = cbi_t[sid][tid].tab;
946 var c = cbi_t[sid][tid].container;
947 var n = c.getElementsByTagName('div');
949 if (n.length === 0) {
950 t.style.display = 'none';
952 else if (t.style.display == 'none') {
953 t.style.display = '';
954 t.className += ' cbi-tab-highlighted';
962 if (hl_tabs.length > 0)
963 window.setTimeout(function() {
964 for( var i = 0; i < hl_tabs.length; i++ )
965 hl_tabs[i].className = hl_tabs[i].className.replace(/ cbi-tab-highlighted/g, '');
972 function cbi_validate_form(form, errmsg)
974 /* if triggered by a section removal or addition, don't validate */
975 if( form.cbi_state == 'add-section' || form.cbi_state == 'del-section' )
978 if( form.cbi_validators )
980 for( var i = 0; i < form.cbi_validators.length; i++ )
982 var validator = form.cbi_validators[i];
983 if( !validator() && errmsg )
994 function cbi_validate_reset(form)
997 function() { cbi_validate_form(form, null) }, 100
1003 function cbi_validate_compile(code)
1012 for (var i = 0; i < code.length; i++)
1020 switch (code.charCodeAt(i))
1032 var label = code.substring(pos, i);
1033 label = label.replace(/\\(.)/g, '$1');
1034 label = label.replace(/^[ \t]+/g, '');
1035 label = label.replace(/[ \t]+$/g, '');
1037 if (label && !isNaN(label))
1039 stack.push(parseFloat(label));
1041 else if (label.match(/^(['"]).*\1$/))
1043 stack.push(label.replace(/^(['"])(.*)\1$/, '$2'));
1045 else if (typeof cbi_validators[label] == 'function')
1047 stack.push(cbi_validators[label]);
1052 throw "Syntax error, unhandled token '"+label+"'";
1057 depth += (code.charCodeAt(i) == 40);
1063 if (typeof stack[stack.length-2] != 'function')
1064 throw "Syntax error, argument list follows non-function";
1066 stack[stack.length-1] =
1067 arguments.callee(code.substring(pos, i));
1078 function cbi_validate_field(cbid, optional, type)
1080 var field = (typeof cbid == "string") ? document.getElementById(cbid) : cbid;
1081 var vstack; try { vstack = cbi_validate_compile(type); } catch(e) { };
1083 if (field && vstack && typeof vstack[0] == "function")
1085 var validator = function()
1090 field.className = field.className.replace(/ cbi-input-invalid/g, '');
1093 var value = (field.options && field.options.selectedIndex > -1)
1094 ? field.options[field.options.selectedIndex].value : field.value;
1096 if (!(((value.length == 0) && optional) || vstack[0].apply(value, vstack[1])))
1099 field.className += ' cbi-input-invalid';
1107 if( ! field.form.cbi_validators )
1108 field.form.cbi_validators = [ ];
1110 field.form.cbi_validators.push(validator);
1112 cbi_bind(field, "blur", validator);
1113 cbi_bind(field, "keyup", validator);
1115 if (field.nodeName == 'SELECT')
1117 cbi_bind(field, "change", validator);
1118 cbi_bind(field, "click", validator);
1121 field.setAttribute("cbi_validate", validator);
1122 field.setAttribute("cbi_datatype", type);
1123 field.setAttribute("cbi_optional", (!!optional).toString());
1127 var fcbox = document.getElementById('cbi.combobox.' + field.id);
1129 cbi_validate_field(fcbox, optional, type);
1133 function cbi_row_swap(elem, up, store)
1135 var tr = elem.parentNode;
1136 while (tr && tr.nodeName.toLowerCase() != 'tr')
1142 var table = tr.parentNode;
1143 while (table && table.nodeName.toLowerCase() != 'table')
1144 table = table.parentNode;
1150 var e = up ? table.rows.length : table.rows.length - 1;
1152 for (var idx = s; idx < e; idx++)
1154 if (table.rows[idx] == tr)
1157 tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]);
1159 tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]);
1166 for (idx = 2; idx < table.rows.length; idx++)
1168 table.rows[idx].className = table.rows[idx].className.replace(
1169 /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx % 2))
1172 if (table.rows[idx].id && table.rows[idx].id.match(/-([^\-]+)$/) )
1173 ids.push(RegExp.$1);
1176 var input = document.getElementById(store);
1178 input.value = ids.join(' ');
1183 function cbi_tag_last(container)
1187 for (var i = 0; i < container.childNodes.length; i++)
1189 var c = container.childNodes[i];
1190 if (c.nodeType == 1 && c.nodeName.toLowerCase() == 'div')
1192 c.className = c.className.replace(/ cbi-value-last$/, '');
1199 last.className += ' cbi-value-last';
1203 String.prototype.serialize = function()
1220 for( var i = 0; i < o.length; i++ )
1221 s += (s ? ', ' : '') + String.serialize(o[i]);
1223 return '[ ' + s + ' ]';
1232 s += (s ? ', ' : '') + k + ': ' + String.serialize(o[k]);
1234 return '{ ' + s + ' }';
1241 if( o.match(/[^a-zA-Z0-9_,.: -]/) )
1242 return 'decodeURIComponent("' + encodeURIComponent(o) + '")';
1246 return '"' + o + '"';
1251 return o.toString();
1255 String.prototype.format = function()
1260 var html_esc = [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1261 var quot_esc = [/"/g, '"', /'/g, '''];
1263 function esc(s, r) {
1264 for( var i = 0; i < r.length; i += 2 )
1265 s = s.replace(r[i], r[i+1]);
1271 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/;
1272 var a = b = [], numSubstitutions = 0, numMatches = 0;
1274 while( a = re.exec(str) )
1277 var leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5];
1278 var pPrecision = a[6], pType = a[7];
1288 if (numSubstitutions < arguments.length)
1290 var param = arguments[numSubstitutions++];
1293 if (pPad && pPad.substr(0,1) == "'")
1294 pad = leftpart.substr(1,1);
1298 var justifyRight = true;
1299 if (pJustify && pJustify === "-")
1300 justifyRight = false;
1304 minLength = parseInt(pMinLength);
1307 if (pPrecision && pType == 'f')
1308 precision = parseInt(pPrecision.substring(1));
1315 subst = (parseInt(param) || 0).toString(2);
1319 subst = String.fromCharCode(parseInt(param) || 0);
1323 subst = (parseInt(param) || 0);
1327 subst = Math.abs(parseInt(param) || 0);
1331 subst = (precision > -1)
1332 ? ((parseFloat(param) || 0.0)).toFixed(precision)
1333 : (parseFloat(param) || 0.0);
1337 subst = (parseInt(param) || 0).toString(8);
1345 subst = ('' + (parseInt(param) || 0).toString(16)).toLowerCase();
1349 subst = ('' + (parseInt(param) || 0).toString(16)).toUpperCase();
1353 subst = esc(param, html_esc);
1357 subst = esc(param, quot_esc);
1361 subst = String.serialize(param);
1368 var ts = (param || 0);
1371 tm = Math.floor(ts / 60);
1376 th = Math.floor(tm / 60);
1381 td = Math.floor(th / 24);
1386 ? String.format('%dd %dh %dm %ds', td, th, tm, ts)
1387 : String.format('%dh %dm %ds', th, tm, ts);
1392 var mf = pMinLength ? parseInt(pMinLength) : 1000;
1393 var pr = pPrecision ? Math.floor(10*parseFloat('0'+pPrecision)) : 2;
1396 var val = parseFloat(param || 0);
1397 var units = [ '', 'K', 'M', 'G', 'T', 'P', 'E' ];
1399 for (i = 0; (i < units.length) && (val > mf); i++)
1402 subst = val.toFixed(pr) + ' ' + units[i];
1408 out += leftpart + subst;
1409 str = str.substr(m.length);
1415 String.prototype.nobr = function()
1417 return this.replace(/[\s\n]+/g, ' ');
1420 String.serialize = function()
1423 for (var i = 1; i < arguments.length; i++)
1424 a.push(arguments[i]);
1425 return ''.serialize.apply(arguments[0], a);
1428 String.format = function()
1431 for (var i = 1; i < arguments.length; i++)
1432 a.push(arguments[i]);
1433 return ''.format.apply(arguments[0], a);
1436 String.nobr = function()
1439 for (var i = 1; i < arguments.length; i++)
1440 a.push(arguments[i]);
1441 return ''.nobr.apply(arguments[0], a);