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);
494 // hide optionals widget if no choices remaining
495 if (parent.parentNode && parent.getAttribute('data-optionals'))
496 parent.parentNode.style.display = (parent.options.length <= 1) ? 'none' : '';
499 if (entry && entry.parent) {
501 cbi_tag_last(parent);
509 function cbi_init() {
510 var nodes = document.querySelectorAll('[data-depends]');
512 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
513 var index = parseInt(node.getAttribute('data-index'), 10);
514 var depends = JSON.parse(node.getAttribute('data-depends'));
515 if (!isNaN(index) && depends.length > 0) {
516 for (var alt = 0; alt < depends.length; alt++) {
517 cbi_d_add(node, depends[alt], index);
522 nodes = document.querySelectorAll('[data-update]');
524 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
525 var events = node.getAttribute('data-update').split(' ');
526 for (var j = 0, event; (event = events[j]) !== undefined; j++) {
527 cbi_bind(node, event, cbi_d_update);
534 function cbi_bind(obj, type, callback, mode) {
535 if (!obj.addEventListener) {
536 obj.attachEvent('on' + type,
538 var e = window.event;
540 if (!e.target && e.srcElement)
541 e.target = e.srcElement;
543 return !!callback(e);
547 obj.addEventListener(type, callback, !!mode);
552 function cbi_combobox(id, values, def, man, focus) {
553 var selid = "cbi.combobox." + id;
554 if (document.getElementById(selid)) {
558 var obj = document.getElementById(id)
559 var sel = document.createElement("select");
561 sel.className = obj.className.replace(/cbi-input-text/, 'cbi-input-select');
563 if (obj.nextSibling) {
564 obj.parentNode.insertBefore(sel, obj.nextSibling);
566 obj.parentNode.appendChild(sel);
569 var dt = obj.getAttribute('cbi_datatype');
570 var op = obj.getAttribute('cbi_optional');
573 cbi_validate_field(sel, op == 'true', dt);
575 if (!values[obj.value]) {
576 if (obj.value == "") {
577 var optdef = document.createElement("option");
579 optdef.appendChild(document.createTextNode(def));
580 sel.appendChild(optdef);
582 var opt = document.createElement("option");
583 opt.value = obj.value;
584 opt.selected = "selected";
585 opt.appendChild(document.createTextNode(obj.value));
586 sel.appendChild(opt);
590 for (var i in values) {
591 var opt = document.createElement("option");
594 if (obj.value == i) {
595 opt.selected = "selected";
598 opt.appendChild(document.createTextNode(values[i]));
599 sel.appendChild(opt);
602 var optman = document.createElement("option");
604 optman.appendChild(document.createTextNode(man));
605 sel.appendChild(optman);
607 obj.style.display = "none";
609 cbi_bind(sel, "change", function() {
610 if (sel.selectedIndex == sel.options.length - 1) {
611 obj.style.display = "inline";
613 sel.parentNode.removeChild(sel);
616 obj.value = sel.options[sel.selectedIndex].value;
626 // Retrigger validation in select
633 function cbi_combobox_init(id, values, def, man) {
634 var obj = document.getElementById(id);
635 cbi_bind(obj, "blur", function() {
636 cbi_combobox(id, values, def, man, true);
638 cbi_combobox(id, values, def, man, false);
641 function cbi_filebrowser(id, url, defpath) {
642 var field = document.getElementById(id);
643 var browser = window.open(
644 url + ( field.value || defpath || '' ) + '?field=' + id,
645 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
651 function cbi_browser_init(id, respath, url, defpath)
653 function cbi_browser_btnclick(e) {
654 cbi_filebrowser(id, url, defpath);
658 var field = document.getElementById(id);
660 var btn = document.createElement('img');
661 btn.className = 'cbi-image-button';
662 btn.src = respath + '/cbi/folder.gif';
663 field.parentNode.insertBefore(btn, field.nextSibling);
665 cbi_bind(btn, 'click', cbi_browser_btnclick);
668 function cbi_dynlist_init(name, respath, datatype, optional, url, defpath, choices)
670 var input0 = document.getElementsByName(name)[0];
671 var prefix = input0.name;
672 var parent = input0.parentNode;
673 var holder = input0.placeholder;
677 function cbi_dynlist_redraw(focus, add, del)
681 while (parent.firstChild)
683 var n = parent.firstChild;
684 var i = parseInt(n.index);
688 if (n.nodeName.toLowerCase() == 'input')
689 values.push(n.value || '');
690 else if (n.nodeName.toLowerCase() == 'select')
691 values[values.length-1] = n.options[n.selectedIndex].value;
694 parent.removeChild(n);
700 values.splice(focus, 0, '');
702 else if (values.length == 0)
708 for (var i = 0; i < values.length; i++)
710 var t = document.createElement('input');
711 t.id = prefix + '.' + (i+1);
716 t.className = 'cbi-input-text';
718 if (i == 0 && holder)
720 t.placeholder = holder;
723 var b = document.createElement('img');
724 b.src = respath + ((i+1) < values.length ? '/cbi/remove.gif' : '/cbi/add.gif');
725 b.className = 'cbi-image-button';
727 parent.appendChild(t);
728 parent.appendChild(b);
729 if (datatype == 'file')
731 cbi_browser_init(t.id, respath, url, defpath);
734 parent.appendChild(document.createElement('br'));
738 cbi_validate_field(t.id, ((i+1) == values.length) || optional, datatype);
743 cbi_combobox_init(t.id, choices[0], '', choices[1]);
746 cbi_bind(b, 'keydown', cbi_dynlist_keydown);
747 cbi_bind(b, 'keypress', cbi_dynlist_keypress);
749 if (i == focus || -i == focus)
754 cbi_bind(t, 'keydown', cbi_dynlist_keydown);
755 cbi_bind(t, 'keypress', cbi_dynlist_keypress);
761 else if (-i == focus)
765 /* force cursor to end */
772 cbi_bind(b, 'click', cbi_dynlist_btnclick);
776 function cbi_dynlist_keypress(ev)
778 ev = ev ? ev : window.event;
780 var se = ev.target ? ev.target : ev.srcElement;
782 if (se.nodeType == 3)
787 /* backspace, delete */
790 if (se.value.length == 0)
792 if (ev.preventDefault)
800 /* enter, arrow up, arrow down */
804 if (ev.preventDefault)
813 function cbi_dynlist_keydown(ev)
815 ev = ev ? ev : window.event;
817 var se = ev.target ? ev.target : ev.srcElement;
819 if (se.nodeType == 3)
822 var prev = se.previousSibling;
823 while (prev && prev.name != name)
824 prev = prev.previousSibling;
826 var next = se.nextSibling;
827 while (next && next.name != name)
828 next = next.nextSibling;
830 /* advance one further in combobox case */
831 if (next && next.nextSibling.name == name)
832 next = next.nextSibling;
836 /* backspace, delete */
839 var del = (se.nodeName.toLowerCase() == 'select')
840 ? true : (se.value.length == 0);
844 if (ev.preventDefault)
847 var focus = se.index;
851 cbi_dynlist_redraw(focus, -1, se.index);
860 cbi_dynlist_redraw(-1, se.index, -1);
881 function cbi_dynlist_btnclick(ev)
883 ev = ev ? ev : window.event;
885 var se = ev.target ? ev.target : ev.srcElement;
886 var input = se.previousSibling;
887 while (input && input.name != name) {
888 input = input.previousSibling;
891 if (se.src.indexOf('remove') > -1)
895 cbi_dynlist_keydown({
902 cbi_dynlist_keydown({
911 cbi_dynlist_redraw(NaN, -1, -1);
915 function cbi_t_add(section, tab) {
916 var t = document.getElementById('tab.' + section + '.' + tab);
917 var c = document.getElementById('container.' + section + '.' + tab);
920 cbi_t[section] = (cbi_t[section] || [ ]);
921 cbi_t[section][tab] = { 'tab': t, 'container': c, 'cid': c.id };
925 function cbi_t_switch(section, tab) {
926 if( cbi_t[section] && cbi_t[section][tab] ) {
927 var o = cbi_t[section][tab];
928 var h = document.getElementById('tab.' + section);
929 for( var tid in cbi_t[section] ) {
930 var o2 = cbi_t[section][tid];
931 if( o.tab.id != o2.tab.id ) {
932 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
933 o2.container.style.display = 'none';
937 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
938 o2.container.style.display = 'block';
945 function cbi_t_update() {
949 for( var sid in cbi_t )
950 for( var tid in cbi_t[sid] )
952 var t = cbi_t[sid][tid].tab;
953 var c = cbi_t[sid][tid].container;
955 if (!c.firstElementChild) {
956 t.style.display = 'none';
958 else if (t.style.display == 'none') {
959 t.style.display = '';
960 t.className += ' cbi-tab-highlighted';
968 if (hl_tabs.length > 0)
969 window.setTimeout(function() {
970 for( var i = 0; i < hl_tabs.length; i++ )
971 hl_tabs[i].className = hl_tabs[i].className.replace(/ cbi-tab-highlighted/g, '');
978 function cbi_validate_form(form, errmsg)
980 /* if triggered by a section removal or addition, don't validate */
981 if( form.cbi_state == 'add-section' || form.cbi_state == 'del-section' )
984 if( form.cbi_validators )
986 for( var i = 0; i < form.cbi_validators.length; i++ )
988 var validator = form.cbi_validators[i];
989 if( !validator() && errmsg )
1000 function cbi_validate_reset(form)
1003 function() { cbi_validate_form(form, null) }, 100
1009 function cbi_validate_compile(code)
1018 for (var i = 0; i < code.length; i++)
1026 switch (code.charCodeAt(i))
1038 var label = code.substring(pos, i);
1039 label = label.replace(/\\(.)/g, '$1');
1040 label = label.replace(/^[ \t]+/g, '');
1041 label = label.replace(/[ \t]+$/g, '');
1043 if (label && !isNaN(label))
1045 stack.push(parseFloat(label));
1047 else if (label.match(/^(['"]).*\1$/))
1049 stack.push(label.replace(/^(['"])(.*)\1$/, '$2'));
1051 else if (typeof cbi_validators[label] == 'function')
1053 stack.push(cbi_validators[label]);
1058 throw "Syntax error, unhandled token '"+label+"'";
1063 depth += (code.charCodeAt(i) == 40);
1069 if (typeof stack[stack.length-2] != 'function')
1070 throw "Syntax error, argument list follows non-function";
1072 stack[stack.length-1] =
1073 arguments.callee(code.substring(pos, i));
1084 function cbi_validate_field(cbid, optional, type)
1086 var field = (typeof cbid == "string") ? document.getElementById(cbid) : cbid;
1087 var vstack; try { vstack = cbi_validate_compile(type); } catch(e) { };
1089 if (field && vstack && typeof vstack[0] == "function")
1091 var validator = function()
1096 field.className = field.className.replace(/ cbi-input-invalid/g, '');
1099 var value = (field.options && field.options.selectedIndex > -1)
1100 ? field.options[field.options.selectedIndex].value : field.value;
1102 if (!(((value.length == 0) && optional) || vstack[0].apply(value, vstack[1])))
1105 field.className += ' cbi-input-invalid';
1113 if( ! field.form.cbi_validators )
1114 field.form.cbi_validators = [ ];
1116 field.form.cbi_validators.push(validator);
1118 cbi_bind(field, "blur", validator);
1119 cbi_bind(field, "keyup", validator);
1121 if (field.nodeName == 'SELECT')
1123 cbi_bind(field, "change", validator);
1124 cbi_bind(field, "click", validator);
1127 field.setAttribute("cbi_validate", validator);
1128 field.setAttribute("cbi_datatype", type);
1129 field.setAttribute("cbi_optional", (!!optional).toString());
1133 var fcbox = document.getElementById('cbi.combobox.' + field.id);
1135 cbi_validate_field(fcbox, optional, type);
1139 function cbi_row_swap(elem, up, store)
1141 var tr = elem.parentNode;
1142 while (tr && tr.nodeName.toLowerCase() != 'tr')
1148 var table = tr.parentNode;
1149 while (table && table.nodeName.toLowerCase() != 'table')
1150 table = table.parentNode;
1156 var e = up ? table.rows.length : table.rows.length - 1;
1158 for (var idx = s; idx < e; idx++)
1160 if (table.rows[idx] == tr)
1163 tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]);
1165 tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]);
1172 for (idx = 2; idx < table.rows.length; idx++)
1174 table.rows[idx].className = table.rows[idx].className.replace(
1175 /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx % 2))
1178 if (table.rows[idx].id && table.rows[idx].id.match(/-([^\-]+)$/) )
1179 ids.push(RegExp.$1);
1182 var input = document.getElementById(store);
1184 input.value = ids.join(' ');
1189 function cbi_tag_last(container)
1193 for (var i = 0; i < container.childNodes.length; i++)
1195 var c = container.childNodes[i];
1196 if (c.nodeType == 1 && c.nodeName.toLowerCase() == 'div')
1198 c.className = c.className.replace(/ cbi-value-last$/, '');
1205 last.className += ' cbi-value-last';
1209 String.prototype.serialize = function()
1226 for( var i = 0; i < o.length; i++ )
1227 s += (s ? ', ' : '') + String.serialize(o[i]);
1229 return '[ ' + s + ' ]';
1238 s += (s ? ', ' : '') + k + ': ' + String.serialize(o[k]);
1240 return '{ ' + s + ' }';
1247 if( o.match(/[^a-zA-Z0-9_,.: -]/) )
1248 return 'decodeURIComponent("' + encodeURIComponent(o) + '")';
1252 return '"' + o + '"';
1257 return o.toString();
1261 String.prototype.format = function()
1266 var html_esc = [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1267 var quot_esc = [/"/g, '"', /'/g, '''];
1269 function esc(s, r) {
1270 for( var i = 0; i < r.length; i += 2 )
1271 s = s.replace(r[i], r[i+1]);
1277 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/;
1278 var a = b = [], numSubstitutions = 0, numMatches = 0;
1280 while( a = re.exec(str) )
1283 var leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5];
1284 var pPrecision = a[6], pType = a[7];
1294 if (numSubstitutions < arguments.length)
1296 var param = arguments[numSubstitutions++];
1299 if (pPad && pPad.substr(0,1) == "'")
1300 pad = leftpart.substr(1,1);
1304 var justifyRight = true;
1305 if (pJustify && pJustify === "-")
1306 justifyRight = false;
1310 minLength = parseInt(pMinLength);
1313 if (pPrecision && pType == 'f')
1314 precision = parseInt(pPrecision.substring(1));
1321 subst = (parseInt(param) || 0).toString(2);
1325 subst = String.fromCharCode(parseInt(param) || 0);
1329 subst = (parseInt(param) || 0);
1333 subst = Math.abs(parseInt(param) || 0);
1337 subst = (precision > -1)
1338 ? ((parseFloat(param) || 0.0)).toFixed(precision)
1339 : (parseFloat(param) || 0.0);
1343 subst = (parseInt(param) || 0).toString(8);
1351 subst = ('' + (parseInt(param) || 0).toString(16)).toLowerCase();
1355 subst = ('' + (parseInt(param) || 0).toString(16)).toUpperCase();
1359 subst = esc(param, html_esc);
1363 subst = esc(param, quot_esc);
1367 subst = String.serialize(param);
1374 var ts = (param || 0);
1377 tm = Math.floor(ts / 60);
1382 th = Math.floor(tm / 60);
1387 td = Math.floor(th / 24);
1392 ? String.format('%dd %dh %dm %ds', td, th, tm, ts)
1393 : String.format('%dh %dm %ds', th, tm, ts);
1398 var mf = pMinLength ? parseInt(pMinLength) : 1000;
1399 var pr = pPrecision ? Math.floor(10*parseFloat('0'+pPrecision)) : 2;
1402 var val = parseFloat(param || 0);
1403 var units = [ '', 'K', 'M', 'G', 'T', 'P', 'E' ];
1405 for (i = 0; (i < units.length) && (val > mf); i++)
1408 subst = val.toFixed(pr) + ' ' + units[i];
1414 out += leftpart + subst;
1415 str = str.substr(m.length);
1421 String.prototype.nobr = function()
1423 return this.replace(/[\s\n]+/g, ' ');
1426 String.serialize = function()
1429 for (var i = 1; i < arguments.length; i++)
1430 a.push(arguments[i]);
1431 return ''.serialize.apply(arguments[0], a);
1434 String.format = function()
1437 for (var i = 1; i < arguments.length; i++)
1438 a.push(arguments[i]);
1439 return ''.format.apply(arguments[0], a);
1442 String.nobr = function()
1445 for (var i = 1; i < arguments.length; i++)
1446 a.push(arguments[i]);
1447 return ''.nobr.apply(arguments[0], a);