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
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);
142 'host': function(ipv4only)
144 return cbi_validators.hostname.apply(this) ||
145 ((ipv4only != 1) && cbi_validators.ipaddr.apply(this)) ||
146 ((ipv4only == 1) && cb_validators.ip4addr.apply(this));
149 'hostname': function()
151 if (this.length <= 253)
152 return (this.match(/^[a-zA-Z0-9]+$/) != null ||
153 (this.match(/^[a-zA-Z0-9_][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$/) &&
154 this.match(/[^0-9.]/)));
159 'network': function()
161 return cbi_validators.uciname.apply(this) ||
162 cbi_validators.host.apply(this);
165 'hostport': function(ipv4only)
167 var hp = this.split(/:/);
170 return (cbi_validators.host.apply(hp[0], ipv4only) &&
171 cbi_validators.port.apply(hp[1]));
176 'ip4addrport': function()
178 var hp = this.split(/:/);
181 return (cbi_validators.ipaddr.apply(hp[0]) &&
182 cbi_validators.port.apply(hp[1]));
186 'ipaddrport': function(bracket)
188 if (this.match(/^([^\[\]:]+):([^:]+)$/)) {
191 return (cbi_validators.ip4addr.apply(addr) &&
192 cbi_validators.port.apply(port));
193 } else if ((bracket == 1) && (this.match(/^\[(.+)\]:([^:]+)$/))) {
196 return (cbi_validators.ip6addr.apply(addr) &&
197 cbi_validators.port.apply(port));
198 } else if ((bracket != 1) && (this.match(/^([^\[\]]+):([^:]+)$/))) {
201 return (cbi_validators.ip6addr.apply(addr) &&
202 cbi_validators.port.apply(port));
213 return (v.match(/^[a-fA-F0-9]{64}$/) != null);
215 return (v.length >= 8) && (v.length <= 63);
222 if ( v.substr(0,2) == 's:' )
225 if( (v.length == 10) || (v.length == 26) )
226 return (v.match(/^[a-fA-F0-9]{10,26}$/) != null);
228 return (v.length == 5) || (v.length == 13);
231 'uciname': function()
233 return (this.match(/^[a-zA-Z0-9_]+$/) != null);
236 'range': function(min, max)
238 var val = parseFloat(this);
239 if (!isNaN(min) && !isNaN(max) && !isNaN(val))
240 return ((val >= min) && (val <= max));
247 var val = parseFloat(this);
248 if (!isNaN(min) && !isNaN(val))
256 var val = parseFloat(this);
257 if (!isNaN(max) && !isNaN(val))
263 'rangelength': function(min, max)
266 if (!isNaN(min) && !isNaN(max))
267 return ((val.length >= min) && (val.length <= max));
272 'minlength': function(min)
276 return (val.length >= min);
281 'maxlength': function(max)
285 return (val.length <= max);
292 for (var i = 0; i < arguments.length; i += 2)
294 if (typeof arguments[i] != 'function')
296 if (arguments[i] == this)
300 else if (arguments[i].apply(this, arguments[i+1]))
310 for (var i = 0; i < arguments.length; i += 2)
312 if (typeof arguments[i] != 'function')
314 if (arguments[i] != this)
318 else if (!arguments[i].apply(this, arguments[i+1]))
328 return cbi_validators.or.apply(
329 this.replace(/^[ \t]*![ \t]*/, ''), arguments);
332 'list': function(subvalidator, subargs)
334 if (typeof subvalidator != 'function')
337 var tokens = this.match(/[^ \t]+/g);
338 for (var i = 0; i < tokens.length; i++)
339 if (!subvalidator.apply(tokens[i], subargs))
344 'phonedigit': function()
346 return (this.match(/^[0-9\*#!\.]+$/) != null);
348 'timehhmmss': function()
350 return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null);
352 'dateyyyymmdd': function()
357 if (this.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)) {
358 var year = RegExp.$1;
359 var month = RegExp.$2;
362 var days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30 , 31, 30, 31 ];
363 function is_leap_year(year) {
364 return ((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0);
366 function get_days_in_month(month, year) {
367 if ((month == 2) && is_leap_year(year)) {
370 return days_in_month[month];
373 /* Firewall rules in the past don't make sense */
377 if ((month <= 0) || (month > 12)) {
380 if ((day <= 0) || (day > get_days_in_month(month, year))) {
392 function cbi_d_add(field, dep, next) {
393 var obj = document.getElementById(field);
396 for (var i=0; i<cbi_d.length; i++) {
397 if (cbi_d[i].id == field) {
406 "parent": obj.parentNode.id,
410 cbi_d.unshift(entry);
416 function cbi_d_checkvalue(target, ref) {
417 var t = document.getElementById(target);
421 var tl = document.getElementsByName(target);
423 if( tl.length > 0 && (tl[0].type == 'radio' || tl[0].type == 'checkbox'))
424 for( var i = 0; i < tl.length; i++ )
425 if( tl[i].checked ) {
430 value = value ? value : "";
431 } else if (!t.value) {
436 if (t.type == "checkbox") {
437 value = t.checked ? value : "";
441 return (value == ref)
444 function cbi_d_check(deps) {
447 for (var i=0; i<deps.length; i++) {
450 for (var j in deps[i]) {
451 if (j == "!reverse") {
453 } else if (j == "!default") {
457 istat = (istat && cbi_d_checkvalue(j, deps[i][j]))
467 function cbi_d_update() {
469 for (var i=0; i<cbi_d.length; i++) {
470 var entry = cbi_d[i];
471 var next = document.getElementById(entry.next)
472 var node = document.getElementById(entry.id)
473 var parent = document.getElementById(entry.parent)
475 if (node && node.parentNode && !cbi_d_check(entry.deps)) {
476 node.parentNode.removeChild(node);
479 cbi_c[entry.parent]--;
480 } else if ((!node || !node.parentNode) && cbi_d_check(entry.deps)) {
482 parent.appendChild(entry.node);
484 next.parentNode.insertBefore(entry.node, next);
488 cbi_c[entry.parent]++;
492 if (entry && entry.parent) {
494 cbi_tag_last(parent);
502 function cbi_bind(obj, type, callback, mode) {
503 if (!obj.addEventListener) {
504 obj.attachEvent('on' + type,
506 var e = window.event;
508 if (!e.target && e.srcElement)
509 e.target = e.srcElement;
511 return !!callback(e);
515 obj.addEventListener(type, callback, !!mode);
520 function cbi_combobox(id, values, def, man) {
521 var selid = "cbi.combobox." + id;
522 if (document.getElementById(selid)) {
526 var obj = document.getElementById(id)
527 var sel = document.createElement("select");
529 sel.className = obj.className.replace(/cbi-input-text/, 'cbi-input-select');
531 if (obj.nextSibling) {
532 obj.parentNode.insertBefore(sel, obj.nextSibling);
534 obj.parentNode.appendChild(sel);
537 var dt = obj.getAttribute('cbi_datatype');
538 var op = obj.getAttribute('cbi_optional');
541 cbi_validate_field(sel, op == 'true', dt);
543 if (!values[obj.value]) {
544 if (obj.value == "") {
545 var optdef = document.createElement("option");
547 optdef.appendChild(document.createTextNode(def));
548 sel.appendChild(optdef);
550 var opt = document.createElement("option");
551 opt.value = obj.value;
552 opt.selected = "selected";
553 opt.appendChild(document.createTextNode(obj.value));
554 sel.appendChild(opt);
558 for (var i in values) {
559 var opt = document.createElement("option");
562 if (obj.value == i) {
563 opt.selected = "selected";
566 opt.appendChild(document.createTextNode(values[i]));
567 sel.appendChild(opt);
570 var optman = document.createElement("option");
572 optman.appendChild(document.createTextNode(man));
573 sel.appendChild(optman);
575 obj.style.display = "none";
577 cbi_bind(sel, "change", function() {
578 if (sel.selectedIndex == sel.options.length - 1) {
579 obj.style.display = "inline";
580 sel.parentNode.removeChild(sel);
583 obj.value = sel.options[sel.selectedIndex].value;
593 // Retrigger validation in select
598 function cbi_combobox_init(id, values, def, man) {
599 var obj = document.getElementById(id);
600 cbi_bind(obj, "blur", function() {
601 cbi_combobox(id, values, def, man)
603 cbi_combobox(id, values, def, man);
606 function cbi_filebrowser(id, url, defpath) {
607 var field = document.getElementById(id);
608 var browser = window.open(
609 url + ( field.value || defpath || '' ) + '?field=' + id,
610 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
616 function cbi_browser_init(id, respath, url, defpath)
618 function cbi_browser_btnclick(e) {
619 cbi_filebrowser(id, url, defpath);
623 var field = document.getElementById(id);
625 var btn = document.createElement('img');
626 btn.className = 'cbi-image-button';
627 btn.src = respath + '/cbi/folder.gif';
628 field.parentNode.insertBefore(btn, field.nextSibling);
630 cbi_bind(btn, 'click', cbi_browser_btnclick);
633 function cbi_dynlist_init(name, respath, datatype, optional, url, defpath, choices)
635 var input0 = document.getElementsByName(name)[0];
636 var prefix = input0.name;
637 var parent = input0.parentNode;
638 var holder = input0.placeholder;
642 function cbi_dynlist_redraw(focus, add, del)
646 while (parent.firstChild)
648 var n = parent.firstChild;
649 var i = parseInt(n.index);
653 if (n.nodeName.toLowerCase() == 'input')
654 values.push(n.value || '');
655 else if (n.nodeName.toLowerCase() == 'select')
656 values[values.length-1] = n.options[n.selectedIndex].value;
659 parent.removeChild(n);
665 values.splice(focus, 0, '');
667 else if (values.length == 0)
673 for (var i = 0; i < values.length; i++)
675 var t = document.createElement('input');
676 t.id = prefix + '.' + (i+1);
681 t.className = 'cbi-input-text';
683 if (i == 0 && holder)
685 t.placeholder = holder;
688 var b = document.createElement('img');
689 b.src = respath + ((i+1) < values.length ? '/cbi/remove.gif' : '/cbi/add.gif');
690 b.className = 'cbi-image-button';
692 parent.appendChild(t);
693 parent.appendChild(b);
694 if (datatype == 'file')
696 cbi_browser_init(t.id, respath, url, defpath);
699 parent.appendChild(document.createElement('br'));
703 cbi_validate_field(t.id, ((i+1) == values.length) || optional, datatype);
708 cbi_combobox_init(t.id, choices[0], '', choices[1]);
711 cbi_bind(b, 'keydown', cbi_dynlist_keydown);
712 cbi_bind(b, 'keypress', cbi_dynlist_keypress);
714 if (i == focus || -i == focus)
719 cbi_bind(t, 'keydown', cbi_dynlist_keydown);
720 cbi_bind(t, 'keypress', cbi_dynlist_keypress);
726 else if (-i == focus)
730 /* force cursor to end */
737 cbi_bind(b, 'click', cbi_dynlist_btnclick);
741 function cbi_dynlist_keypress(ev)
743 ev = ev ? ev : window.event;
745 var se = ev.target ? ev.target : ev.srcElement;
747 if (se.nodeType == 3)
752 /* backspace, delete */
755 if (se.value.length == 0)
757 if (ev.preventDefault)
765 /* enter, arrow up, arrow down */
769 if (ev.preventDefault)
778 function cbi_dynlist_keydown(ev)
780 ev = ev ? ev : window.event;
782 var se = ev.target ? ev.target : ev.srcElement;
784 if (se.nodeType == 3)
787 var prev = se.previousSibling;
788 while (prev && prev.name != name)
789 prev = prev.previousSibling;
791 var next = se.nextSibling;
792 while (next && next.name != name)
793 next = next.nextSibling;
795 /* advance one further in combobox case */
796 if (next && next.nextSibling.name == name)
797 next = next.nextSibling;
801 /* backspace, delete */
804 var del = (se.nodeName.toLowerCase() == 'select')
805 ? true : (se.value.length == 0);
809 if (ev.preventDefault)
812 var focus = se.index;
816 cbi_dynlist_redraw(focus, -1, se.index);
825 cbi_dynlist_redraw(-1, se.index, -1);
846 function cbi_dynlist_btnclick(ev)
848 ev = ev ? ev : window.event;
850 var se = ev.target ? ev.target : ev.srcElement;
851 var input = se.previousSibling;
852 while (input && input.name != name) {
853 input = input.previousSibling;
856 if (se.src.indexOf('remove') > -1)
860 cbi_dynlist_keydown({
867 cbi_dynlist_keydown({
876 cbi_dynlist_redraw(NaN, -1, -1);
879 //Hijacks the CBI form to send via XHR (requires Prototype)
880 function cbi_hijack_forms(layer, win, fail, load) {
881 var forms = layer.getElementsByTagName('form');
882 for (var i=0; i<forms.length; i++) {
883 $(forms[i]).observe('submit', function(event) {
884 // Prevent the form from also submitting the regular way
888 event.element().request({
901 function cbi_t_add(section, tab) {
902 var t = document.getElementById('tab.' + section + '.' + tab);
903 var c = document.getElementById('container.' + section + '.' + tab);
906 cbi_t[section] = (cbi_t[section] || [ ]);
907 cbi_t[section][tab] = { 'tab': t, 'container': c, 'cid': c.id };
911 function cbi_t_switch(section, tab) {
912 if( cbi_t[section] && cbi_t[section][tab] ) {
913 var o = cbi_t[section][tab];
914 var h = document.getElementById('tab.' + section);
915 for( var tid in cbi_t[section] ) {
916 var o2 = cbi_t[section][tid];
917 if( o.tab.id != o2.tab.id ) {
918 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
919 o2.container.style.display = 'none';
923 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
924 o2.container.style.display = 'block';
931 function cbi_t_update() {
935 for( var sid in cbi_t )
936 for( var tid in cbi_t[sid] )
938 if( cbi_c[cbi_t[sid][tid].cid] == 0 ) {
939 cbi_t[sid][tid].tab.style.display = 'none';
941 else if( cbi_t[sid][tid].tab && cbi_t[sid][tid].tab.style.display == 'none' ) {
942 cbi_t[sid][tid].tab.style.display = '';
944 var t = cbi_t[sid][tid].tab;
945 t.className += ' cbi-tab-highlighted';
949 cbi_tag_last(cbi_t[sid][tid].container);
953 if( hl_tabs.length > 0 )
954 window.setTimeout(function() {
955 for( var i = 0; i < hl_tabs.length; i++ )
956 hl_tabs[i].className = hl_tabs[i].className.replace(/ cbi-tab-highlighted/g, '');
963 function cbi_validate_form(form, errmsg)
965 /* if triggered by a section removal or addition, don't validate */
966 if( form.cbi_state == 'add-section' || form.cbi_state == 'del-section' )
969 if( form.cbi_validators )
971 for( var i = 0; i < form.cbi_validators.length; i++ )
973 var validator = form.cbi_validators[i];
974 if( !validator() && errmsg )
985 function cbi_validate_reset(form)
988 function() { cbi_validate_form(form, null) }, 100
994 function cbi_validate_compile(code)
1003 for (var i = 0; i < code.length; i++)
1011 switch (code.charCodeAt(i))
1023 var label = code.substring(pos, i);
1024 label = label.replace(/\\(.)/g, '$1');
1025 label = label.replace(/^[ \t]+/g, '');
1026 label = label.replace(/[ \t]+$/g, '');
1028 if (label && !isNaN(label))
1030 stack.push(parseFloat(label));
1032 else if (label.match(/^(['"]).*\1$/))
1034 stack.push(label.replace(/^(['"])(.*)\1$/, '$2'));
1036 else if (typeof cbi_validators[label] == 'function')
1038 stack.push(cbi_validators[label]);
1043 throw "Syntax error, unhandled token '"+label+"'";
1048 depth += (code.charCodeAt(i) == 40);
1054 if (typeof stack[stack.length-2] != 'function')
1055 throw "Syntax error, argument list follows non-function";
1057 stack[stack.length-1] =
1058 arguments.callee(code.substring(pos, i));
1069 function cbi_validate_field(cbid, optional, type)
1071 var field = (typeof cbid == "string") ? document.getElementById(cbid) : cbid;
1072 var vstack; try { vstack = cbi_validate_compile(type); } catch(e) { };
1074 if (field && vstack && typeof vstack[0] == "function")
1076 var validator = function()
1081 field.className = field.className.replace(/ cbi-input-invalid/g, '');
1084 var value = (field.options && field.options.selectedIndex > -1)
1085 ? field.options[field.options.selectedIndex].value : field.value;
1087 if (!(((value.length == 0) && optional) || vstack[0].apply(value, vstack[1])))
1090 field.className += ' cbi-input-invalid';
1098 if( ! field.form.cbi_validators )
1099 field.form.cbi_validators = [ ];
1101 field.form.cbi_validators.push(validator);
1103 cbi_bind(field, "blur", validator);
1104 cbi_bind(field, "keyup", validator);
1106 if (field.nodeName == 'SELECT')
1108 cbi_bind(field, "change", validator);
1109 cbi_bind(field, "click", validator);
1112 field.setAttribute("cbi_validate", validator);
1113 field.setAttribute("cbi_datatype", type);
1114 field.setAttribute("cbi_optional", (!!optional).toString());
1118 var fcbox = document.getElementById('cbi.combobox.' + field.id);
1120 cbi_validate_field(fcbox, optional, type);
1124 function cbi_row_swap(elem, up, store)
1126 var tr = elem.parentNode;
1127 while (tr && tr.nodeName.toLowerCase() != 'tr')
1133 var table = tr.parentNode;
1134 while (table && table.nodeName.toLowerCase() != 'table')
1135 table = table.parentNode;
1141 var e = up ? table.rows.length : table.rows.length - 1;
1143 for (var idx = s; idx < e; idx++)
1145 if (table.rows[idx] == tr)
1148 tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]);
1150 tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]);
1157 for (idx = 2; idx < table.rows.length; idx++)
1159 table.rows[idx].className = table.rows[idx].className.replace(
1160 /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx % 2))
1163 if (table.rows[idx].id && table.rows[idx].id.match(/-([^\-]+)$/) )
1164 ids.push(RegExp.$1);
1167 var input = document.getElementById(store);
1169 input.value = ids.join(' ');
1174 function cbi_tag_last(container)
1178 for (var i = 0; i < container.childNodes.length; i++)
1180 var c = container.childNodes[i];
1181 if (c.nodeType == 1 && c.nodeName.toLowerCase() == 'div')
1183 c.className = c.className.replace(/ cbi-value-last$/, '');
1190 last.className += ' cbi-value-last';
1194 String.prototype.serialize = function()
1211 for( var i = 0; i < o.length; i++ )
1212 s += (s ? ', ' : '') + String.serialize(o[i]);
1214 return '[ ' + s + ' ]';
1223 s += (s ? ', ' : '') + k + ': ' + String.serialize(o[k]);
1225 return '{ ' + s + ' }';
1232 if( o.match(/[^a-zA-Z0-9_,.: -]/) )
1233 return 'decodeURIComponent("' + encodeURIComponent(o) + '")';
1237 return '"' + o + '"';
1242 return o.toString();
1246 String.prototype.format = function()
1251 var html_esc = [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1252 var quot_esc = [/"/g, '"', /'/g, '''];
1254 function esc(s, r) {
1255 for( var i = 0; i < r.length; i += 2 )
1256 s = s.replace(r[i], r[i+1]);
1262 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/;
1263 var a = b = [], numSubstitutions = 0, numMatches = 0;
1265 while( a = re.exec(str) )
1268 var leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5];
1269 var pPrecision = a[6], pType = a[7];
1279 if (numSubstitutions < arguments.length)
1281 var param = arguments[numSubstitutions++];
1284 if (pPad && pPad.substr(0,1) == "'")
1285 pad = leftpart.substr(1,1);
1289 var justifyRight = true;
1290 if (pJustify && pJustify === "-")
1291 justifyRight = false;
1295 minLength = parseInt(pMinLength);
1298 if (pPrecision && pType == 'f')
1299 precision = parseInt(pPrecision.substring(1));
1306 subst = (parseInt(param) || 0).toString(2);
1310 subst = String.fromCharCode(parseInt(param) || 0);
1314 subst = (parseInt(param) || 0);
1318 subst = Math.abs(parseInt(param) || 0);
1322 subst = (precision > -1)
1323 ? ((parseFloat(param) || 0.0)).toFixed(precision)
1324 : (parseFloat(param) || 0.0);
1328 subst = (parseInt(param) || 0).toString(8);
1336 subst = ('' + (parseInt(param) || 0).toString(16)).toLowerCase();
1340 subst = ('' + (parseInt(param) || 0).toString(16)).toUpperCase();
1344 subst = esc(param, html_esc);
1348 subst = esc(param, quot_esc);
1352 subst = String.serialize(param);
1359 var ts = (param || 0);
1362 tm = Math.floor(ts / 60);
1367 th = Math.floor(tm / 60);
1372 td = Math.floor(th / 24);
1377 ? String.format('%dd %dh %dm %ds', td, th, tm, ts)
1378 : String.format('%dh %dm %ds', th, tm, ts);
1383 var mf = pMinLength ? parseInt(pMinLength) : 1000;
1384 var pr = pPrecision ? Math.floor(10*parseFloat('0'+pPrecision)) : 2;
1387 var val = parseFloat(param || 0);
1388 var units = [ '', 'K', 'M', 'G', 'T', 'P', 'E' ];
1390 for (i = 0; (i < units.length) && (val > mf); i++)
1393 subst = val.toFixed(pr) + ' ' + units[i];
1399 out += leftpart + subst;
1400 str = str.substr(m.length);
1406 String.prototype.nobr = function()
1408 return this.replace(/[\s\n]+/g, ' ');
1411 String.serialize = function()
1414 for (var i = 1; i < arguments.length; i++)
1415 a.push(arguments[i]);
1416 return ''.serialize.apply(arguments[0], a);
1419 String.format = function()
1422 for (var i = 1; i < arguments.length; i++)
1423 a.push(arguments[i]);
1424 return ''.format.apply(arguments[0], a);
1427 String.nobr = function()
1430 for (var i = 1; i < arguments.length; i++)
1431 a.push(arguments[i]);
1432 return ''.nobr.apply(arguments[0], a);