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);
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);
164 'hostport': function()
166 var hp = this.split(/:/);
169 return (cbi_validators.host.apply(hp[0]) &&
170 cbi_validators.port.apply(hp[1]));
175 'ipaddrport': function()
177 var hp = this.split(/:/);
180 return (cbi_validators.ipaddr.apply(hp[0]) &&
181 cbi_validators.port.apply(hp[1]));
191 return (v.match(/^[a-fA-F0-9]{64}$/) != null);
193 return (v.length >= 8) && (v.length <= 63);
200 if ( v.substr(0,2) == 's:' )
203 if( (v.length == 10) || (v.length == 26) )
204 return (v.match(/^[a-fA-F0-9]{10,26}$/) != null);
206 return (v.length == 5) || (v.length == 13);
209 'uciname': function()
211 return (this.match(/^[a-zA-Z0-9_]+$/) != null);
214 'range': function(min, max)
216 var val = parseFloat(this);
217 if (!isNaN(min) && !isNaN(max) && !isNaN(val))
218 return ((val >= min) && (val <= max));
225 var val = parseFloat(this);
226 if (!isNaN(min) && !isNaN(val))
234 var val = parseFloat(this);
235 if (!isNaN(max) && !isNaN(val))
241 'rangelength': function(min, max)
244 if (!isNaN(min) && !isNaN(max))
245 return ((val.length >= min) && (val.length <= max));
250 'minlength': function(min)
254 return (val.length >= min);
259 'maxlength': function(max)
263 return (val.length <= max);
270 for (var i = 0; i < arguments.length; i += 2)
272 if (typeof arguments[i] != 'function')
274 if (arguments[i] == this)
278 else if (arguments[i].apply(this, arguments[i+1]))
288 for (var i = 0; i < arguments.length; i += 2)
290 if (typeof arguments[i] != 'function')
292 if (arguments[i] != this)
296 else if (!arguments[i].apply(this, arguments[i+1]))
306 return cbi_validators.or.apply(
307 this.replace(/^[ \t]*![ \t]*/, ''), arguments);
310 'list': function(subvalidator, subargs)
312 if (typeof subvalidator != 'function')
315 var tokens = this.match(/[^ \t]+/g);
316 for (var i = 0; i < tokens.length; i++)
317 if (!subvalidator.apply(tokens[i], subargs))
322 'phonedigit': function()
324 return (this.match(/^[0-9\*#!\.]+$/) != null);
326 'timehhmmss': function()
328 return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null);
330 'dateyyyymmdd': function()
335 if (this.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)) {
336 var year = RegExp.$1;
337 var month = RegExp.$2;
340 var days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30 , 31, 30, 31 ];
341 function is_leap_year(year) {
342 return ((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0);
344 function get_days_in_month(month, year) {
345 if ((month == 2) && is_leap_year(year)) {
348 return days_in_month[month];
351 /* Firewall rules in the past don't make sense */
355 if ((month <= 0) || (month > 12)) {
358 if ((day <= 0) || (day > get_days_in_month(month, year))) {
370 function cbi_d_add(field, dep, next) {
371 var obj = document.getElementById(field);
374 for (var i=0; i<cbi_d.length; i++) {
375 if (cbi_d[i].id == field) {
384 "parent": obj.parentNode.id,
388 cbi_d.unshift(entry);
394 function cbi_d_checkvalue(target, ref) {
395 var t = document.getElementById(target);
399 var tl = document.getElementsByName(target);
401 if( tl.length > 0 && (tl[0].type == 'radio' || tl[0].type == 'checkbox'))
402 for( var i = 0; i < tl.length; i++ )
403 if( tl[i].checked ) {
408 value = value ? value : "";
409 } else if (!t.value) {
414 if (t.type == "checkbox") {
415 value = t.checked ? value : "";
419 return (value == ref)
422 function cbi_d_check(deps) {
425 for (var i=0; i<deps.length; i++) {
428 for (var j in deps[i]) {
429 if (j == "!reverse") {
431 } else if (j == "!default") {
435 istat = (istat && cbi_d_checkvalue(j, deps[i][j]))
445 function cbi_d_update() {
447 for (var i=0; i<cbi_d.length; i++) {
448 var entry = cbi_d[i];
449 var next = document.getElementById(entry.next)
450 var node = document.getElementById(entry.id)
451 var parent = document.getElementById(entry.parent)
453 if (node && node.parentNode && !cbi_d_check(entry.deps)) {
454 node.parentNode.removeChild(node);
457 cbi_c[entry.parent]--;
458 } else if ((!node || !node.parentNode) && cbi_d_check(entry.deps)) {
460 parent.appendChild(entry.node);
462 next.parentNode.insertBefore(entry.node, next);
466 cbi_c[entry.parent]++;
470 if (entry && entry.parent) {
472 cbi_tag_last(parent);
480 function cbi_bind(obj, type, callback, mode) {
481 if (!obj.addEventListener) {
482 obj.attachEvent('on' + type,
484 var e = window.event;
486 if (!e.target && e.srcElement)
487 e.target = e.srcElement;
489 return !!callback(e);
493 obj.addEventListener(type, callback, !!mode);
498 function cbi_combobox(id, values, def, man) {
499 var selid = "cbi.combobox." + id;
500 if (document.getElementById(selid)) {
504 var obj = document.getElementById(id)
505 var sel = document.createElement("select");
507 sel.className = obj.className.replace(/cbi-input-text/, 'cbi-input-select');
509 if (obj.nextSibling) {
510 obj.parentNode.insertBefore(sel, obj.nextSibling);
512 obj.parentNode.appendChild(sel);
515 var dt = obj.getAttribute('cbi_datatype');
516 var op = obj.getAttribute('cbi_optional');
519 cbi_validate_field(sel, op == 'true', dt);
521 if (!values[obj.value]) {
522 if (obj.value == "") {
523 var optdef = document.createElement("option");
525 optdef.appendChild(document.createTextNode(def));
526 sel.appendChild(optdef);
528 var opt = document.createElement("option");
529 opt.value = obj.value;
530 opt.selected = "selected";
531 opt.appendChild(document.createTextNode(obj.value));
532 sel.appendChild(opt);
536 for (var i in values) {
537 var opt = document.createElement("option");
540 if (obj.value == i) {
541 opt.selected = "selected";
544 opt.appendChild(document.createTextNode(values[i]));
545 sel.appendChild(opt);
548 var optman = document.createElement("option");
550 optman.appendChild(document.createTextNode(man));
551 sel.appendChild(optman);
553 obj.style.display = "none";
555 cbi_bind(sel, "change", function() {
556 if (sel.selectedIndex == sel.options.length - 1) {
557 obj.style.display = "inline";
558 sel.parentNode.removeChild(sel);
561 obj.value = sel.options[sel.selectedIndex].value;
571 // Retrigger validation in select
576 function cbi_combobox_init(id, values, def, man) {
577 var obj = document.getElementById(id);
578 cbi_bind(obj, "blur", function() {
579 cbi_combobox(id, values, def, man)
581 cbi_combobox(id, values, def, man);
584 function cbi_filebrowser(id, url, defpath) {
585 var field = document.getElementById(id);
586 var browser = window.open(
587 url + ( field.value || defpath || '' ) + '?field=' + id,
588 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
594 function cbi_browser_init(id, respath, url, defpath)
596 function cbi_browser_btnclick(e) {
597 cbi_filebrowser(id, url, defpath);
601 var field = document.getElementById(id);
603 var btn = document.createElement('img');
604 btn.className = 'cbi-image-button';
605 btn.src = respath + '/cbi/folder.gif';
606 field.parentNode.insertBefore(btn, field.nextSibling);
608 cbi_bind(btn, 'click', cbi_browser_btnclick);
611 function cbi_dynlist_init(name, respath, datatype, optional, url, defpath, choices)
613 var input0 = document.getElementsByName(name)[0];
614 var prefix = input0.name;
615 var parent = input0.parentNode;
616 var holder = input0.placeholder;
620 function cbi_dynlist_redraw(focus, add, del)
624 while (parent.firstChild)
626 var n = parent.firstChild;
627 var i = parseInt(n.index);
631 if (n.nodeName.toLowerCase() == 'input')
632 values.push(n.value || '');
633 else if (n.nodeName.toLowerCase() == 'select')
634 values[values.length-1] = n.options[n.selectedIndex].value;
637 parent.removeChild(n);
643 values.splice(focus, 0, '');
645 else if (values.length == 0)
651 for (var i = 0; i < values.length; i++)
653 var t = document.createElement('input');
654 t.id = prefix + '.' + (i+1);
659 t.className = 'cbi-input-text';
661 if (i == 0 && holder)
663 t.placeholder = holder;
666 var b = document.createElement('img');
667 b.src = respath + ((i+1) < values.length ? '/cbi/remove.gif' : '/cbi/add.gif');
668 b.className = 'cbi-image-button';
670 parent.appendChild(t);
671 parent.appendChild(b);
672 if (datatype == 'file')
674 cbi_browser_init(t.id, respath, url, defpath);
677 parent.appendChild(document.createElement('br'));
681 cbi_validate_field(t.id, ((i+1) == values.length) || optional, datatype);
686 cbi_combobox_init(t.id, choices[0], '', choices[1]);
689 cbi_bind(b, 'keydown', cbi_dynlist_keydown);
690 cbi_bind(b, 'keypress', cbi_dynlist_keypress);
692 if (i == focus || -i == focus)
697 cbi_bind(t, 'keydown', cbi_dynlist_keydown);
698 cbi_bind(t, 'keypress', cbi_dynlist_keypress);
704 else if (-i == focus)
708 /* force cursor to end */
715 cbi_bind(b, 'click', cbi_dynlist_btnclick);
719 function cbi_dynlist_keypress(ev)
721 ev = ev ? ev : window.event;
723 var se = ev.target ? ev.target : ev.srcElement;
725 if (se.nodeType == 3)
730 /* backspace, delete */
733 if (se.value.length == 0)
735 if (ev.preventDefault)
743 /* enter, arrow up, arrow down */
747 if (ev.preventDefault)
756 function cbi_dynlist_keydown(ev)
758 ev = ev ? ev : window.event;
760 var se = ev.target ? ev.target : ev.srcElement;
762 if (se.nodeType == 3)
765 var prev = se.previousSibling;
766 while (prev && prev.name != name)
767 prev = prev.previousSibling;
769 var next = se.nextSibling;
770 while (next && next.name != name)
771 next = next.nextSibling;
773 /* advance one further in combobox case */
774 if (next && next.nextSibling.name == name)
775 next = next.nextSibling;
779 /* backspace, delete */
782 var del = (se.nodeName.toLowerCase() == 'select')
783 ? true : (se.value.length == 0);
787 if (ev.preventDefault)
790 var focus = se.index;
794 cbi_dynlist_redraw(focus, -1, se.index);
803 cbi_dynlist_redraw(-1, se.index, -1);
824 function cbi_dynlist_btnclick(ev)
826 ev = ev ? ev : window.event;
828 var se = ev.target ? ev.target : ev.srcElement;
829 var input = se.previousSibling;
830 while (input && input.name != name) {
831 input = input.previousSibling;
834 if (se.src.indexOf('remove') > -1)
838 cbi_dynlist_keydown({
845 cbi_dynlist_keydown({
854 cbi_dynlist_redraw(NaN, -1, -1);
857 //Hijacks the CBI form to send via XHR (requires Prototype)
858 function cbi_hijack_forms(layer, win, fail, load) {
859 var forms = layer.getElementsByTagName('form');
860 for (var i=0; i<forms.length; i++) {
861 $(forms[i]).observe('submit', function(event) {
862 // Prevent the form from also submitting the regular way
866 event.element().request({
879 function cbi_t_add(section, tab) {
880 var t = document.getElementById('tab.' + section + '.' + tab);
881 var c = document.getElementById('container.' + section + '.' + tab);
884 cbi_t[section] = (cbi_t[section] || [ ]);
885 cbi_t[section][tab] = { 'tab': t, 'container': c, 'cid': c.id };
889 function cbi_t_switch(section, tab) {
890 if( cbi_t[section] && cbi_t[section][tab] ) {
891 var o = cbi_t[section][tab];
892 var h = document.getElementById('tab.' + section);
893 for( var tid in cbi_t[section] ) {
894 var o2 = cbi_t[section][tid];
895 if( o.tab.id != o2.tab.id ) {
896 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
897 o2.container.style.display = 'none';
901 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
902 o2.container.style.display = 'block';
909 function cbi_t_update() {
913 for( var sid in cbi_t )
914 for( var tid in cbi_t[sid] )
916 if( cbi_c[cbi_t[sid][tid].cid] == 0 ) {
917 cbi_t[sid][tid].tab.style.display = 'none';
919 else if( cbi_t[sid][tid].tab && cbi_t[sid][tid].tab.style.display == 'none' ) {
920 cbi_t[sid][tid].tab.style.display = '';
922 var t = cbi_t[sid][tid].tab;
923 t.className += ' cbi-tab-highlighted';
927 cbi_tag_last(cbi_t[sid][tid].container);
931 if( hl_tabs.length > 0 )
932 window.setTimeout(function() {
933 for( var i = 0; i < hl_tabs.length; i++ )
934 hl_tabs[i].className = hl_tabs[i].className.replace(/ cbi-tab-highlighted/g, '');
941 function cbi_validate_form(form, errmsg)
943 /* if triggered by a section removal or addition, don't validate */
944 if( form.cbi_state == 'add-section' || form.cbi_state == 'del-section' )
947 if( form.cbi_validators )
949 for( var i = 0; i < form.cbi_validators.length; i++ )
951 var validator = form.cbi_validators[i];
952 if( !validator() && errmsg )
963 function cbi_validate_reset(form)
966 function() { cbi_validate_form(form, null) }, 100
972 function cbi_validate_compile(code)
981 for (var i = 0; i < code.length; i++)
989 switch (code.charCodeAt(i))
1001 var label = code.substring(pos, i);
1002 label = label.replace(/\\(.)/g, '$1');
1003 label = label.replace(/^[ \t]+/g, '');
1004 label = label.replace(/[ \t]+$/g, '');
1006 if (label && !isNaN(label))
1008 stack.push(parseFloat(label));
1010 else if (label.match(/^(['"]).*\1$/))
1012 stack.push(label.replace(/^(['"])(.*)\1$/, '$2'));
1014 else if (typeof cbi_validators[label] == 'function')
1016 stack.push(cbi_validators[label]);
1021 throw "Syntax error, unhandled token '"+label+"'";
1026 depth += (code.charCodeAt(i) == 40);
1032 if (typeof stack[stack.length-2] != 'function')
1033 throw "Syntax error, argument list follows non-function";
1035 stack[stack.length-1] =
1036 arguments.callee(code.substring(pos, i));
1047 function cbi_validate_field(cbid, optional, type)
1049 var field = (typeof cbid == "string") ? document.getElementById(cbid) : cbid;
1050 var vstack; try { vstack = cbi_validate_compile(type); } catch(e) { };
1052 if (field && vstack && typeof vstack[0] == "function")
1054 var validator = function()
1059 field.className = field.className.replace(/ cbi-input-invalid/g, '');
1062 var value = (field.options && field.options.selectedIndex > -1)
1063 ? field.options[field.options.selectedIndex].value : field.value;
1065 if (!(((value.length == 0) && optional) || vstack[0].apply(value, vstack[1])))
1068 field.className += ' cbi-input-invalid';
1076 if( ! field.form.cbi_validators )
1077 field.form.cbi_validators = [ ];
1079 field.form.cbi_validators.push(validator);
1081 cbi_bind(field, "blur", validator);
1082 cbi_bind(field, "keyup", validator);
1084 if (field.nodeName == 'SELECT')
1086 cbi_bind(field, "change", validator);
1087 cbi_bind(field, "click", validator);
1090 field.setAttribute("cbi_validate", validator);
1091 field.setAttribute("cbi_datatype", type);
1092 field.setAttribute("cbi_optional", (!!optional).toString());
1096 var fcbox = document.getElementById('cbi.combobox.' + field.id);
1098 cbi_validate_field(fcbox, optional, type);
1102 function cbi_row_swap(elem, up, store)
1104 var tr = elem.parentNode;
1105 while (tr && tr.nodeName.toLowerCase() != 'tr')
1111 var table = tr.parentNode;
1112 while (table && table.nodeName.toLowerCase() != 'table')
1113 table = table.parentNode;
1119 var e = up ? table.rows.length : table.rows.length - 1;
1121 for (var idx = s; idx < e; idx++)
1123 if (table.rows[idx] == tr)
1126 tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]);
1128 tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]);
1135 for (idx = 2; idx < table.rows.length; idx++)
1137 table.rows[idx].className = table.rows[idx].className.replace(
1138 /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx % 2))
1141 if (table.rows[idx].id && table.rows[idx].id.match(/-([^\-]+)$/) )
1142 ids.push(RegExp.$1);
1145 var input = document.getElementById(store);
1147 input.value = ids.join(' ');
1152 function cbi_tag_last(container)
1156 for (var i = 0; i < container.childNodes.length; i++)
1158 var c = container.childNodes[i];
1159 if (c.nodeType == 1 && c.nodeName.toLowerCase() == 'div')
1161 c.className = c.className.replace(/ cbi-value-last$/, '');
1168 last.className += ' cbi-value-last';
1172 String.prototype.serialize = function()
1189 for( var i = 0; i < o.length; i++ )
1190 s += (s ? ', ' : '') + String.serialize(o[i]);
1192 return '[ ' + s + ' ]';
1201 s += (s ? ', ' : '') + k + ': ' + String.serialize(o[k]);
1203 return '{ ' + s + ' }';
1210 if( o.match(/[^a-zA-Z0-9_,.: -]/) )
1211 return 'decodeURIComponent("' + encodeURIComponent(o) + '")';
1215 return '"' + o + '"';
1220 return o.toString();
1224 String.prototype.format = function()
1229 var html_esc = [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1230 var quot_esc = [/"/g, '"', /'/g, '''];
1232 function esc(s, r) {
1233 for( var i = 0; i < r.length; i += 2 )
1234 s = s.replace(r[i], r[i+1]);
1240 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/;
1241 var a = b = [], numSubstitutions = 0, numMatches = 0;
1243 while( a = re.exec(str) )
1246 var leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5];
1247 var pPrecision = a[6], pType = a[7];
1257 if (numSubstitutions < arguments.length)
1259 var param = arguments[numSubstitutions++];
1262 if (pPad && pPad.substr(0,1) == "'")
1263 pad = leftpart.substr(1,1);
1267 var justifyRight = true;
1268 if (pJustify && pJustify === "-")
1269 justifyRight = false;
1273 minLength = parseInt(pMinLength);
1276 if (pPrecision && pType == 'f')
1277 precision = parseInt(pPrecision.substring(1));
1284 subst = (parseInt(param) || 0).toString(2);
1288 subst = String.fromCharCode(parseInt(param) || 0);
1292 subst = (parseInt(param) || 0);
1296 subst = Math.abs(parseInt(param) || 0);
1300 subst = (precision > -1)
1301 ? ((parseFloat(param) || 0.0)).toFixed(precision)
1302 : (parseFloat(param) || 0.0);
1306 subst = (parseInt(param) || 0).toString(8);
1314 subst = ('' + (parseInt(param) || 0).toString(16)).toLowerCase();
1318 subst = ('' + (parseInt(param) || 0).toString(16)).toUpperCase();
1322 subst = esc(param, html_esc);
1326 subst = esc(param, quot_esc);
1330 subst = String.serialize(param);
1337 var ts = (param || 0);
1340 tm = Math.floor(ts / 60);
1345 th = Math.floor(tm / 60);
1350 td = Math.floor(th / 24);
1355 ? String.format('%dd %dh %dm %ds', td, th, tm, ts)
1356 : String.format('%dh %dm %ds', th, tm, ts);
1361 var mf = pMinLength ? parseInt(pMinLength) : 1000;
1362 var pr = pPrecision ? Math.floor(10*parseFloat('0'+pPrecision)) : 2;
1365 var val = parseFloat(param || 0);
1366 var units = [ '', 'K', 'M', 'G', 'T', 'P', 'E' ];
1368 for (i = 0; (i < units.length) && (val > mf); i++)
1371 subst = val.toFixed(pr) + ' ' + units[i];
1377 out += leftpart + subst;
1378 str = str.substr(m.length);
1384 String.prototype.nobr = function()
1386 return this.replace(/[\s\n]+/g, ' ');
1389 String.serialize = function()
1392 for (var i = 1; i < arguments.length; i++)
1393 a.push(arguments[i]);
1394 return ''.serialize.apply(arguments[0], a);
1397 String.format = function()
1400 for (var i = 1; i < arguments.length; i++)
1401 a.push(arguments[i]);
1402 return ''.format.apply(arguments[0], a);
1405 String.nobr = function()
1408 for (var i = 1; i < arguments.length; i++)
1409 a.push(arguments[i]);
1410 return ''.nobr.apply(arguments[0], a);