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);
351 function cbi_d_add(field, dep, next) {
352 var obj = document.getElementById(field);
355 for (var i=0; i<cbi_d.length; i++) {
356 if (cbi_d[i].id == field) {
365 "parent": obj.parentNode.id,
369 cbi_d.unshift(entry);
375 function cbi_d_checkvalue(target, ref) {
376 var t = document.getElementById(target);
380 var tl = document.getElementsByName(target);
382 if( tl.length > 0 && (tl[0].type == 'radio' || tl[0].type == 'checkbox'))
383 for( var i = 0; i < tl.length; i++ )
384 if( tl[i].checked ) {
389 value = value ? value : "";
390 } else if (!t.value) {
395 if (t.type == "checkbox") {
396 value = t.checked ? value : "";
400 return (value == ref)
403 function cbi_d_check(deps) {
406 for (var i=0; i<deps.length; i++) {
409 for (var j in deps[i]) {
410 if (j == "!reverse") {
412 } else if (j == "!default") {
416 istat = (istat && cbi_d_checkvalue(j, deps[i][j]))
426 function cbi_d_update() {
428 for (var i=0; i<cbi_d.length; i++) {
429 var entry = cbi_d[i];
430 var next = document.getElementById(entry.next)
431 var node = document.getElementById(entry.id)
432 var parent = document.getElementById(entry.parent)
434 if (node && node.parentNode && !cbi_d_check(entry.deps)) {
435 node.parentNode.removeChild(node);
438 cbi_c[entry.parent]--;
439 } else if ((!node || !node.parentNode) && cbi_d_check(entry.deps)) {
441 parent.appendChild(entry.node);
443 next.parentNode.insertBefore(entry.node, next);
447 cbi_c[entry.parent]++;
451 if (entry && entry.parent) {
453 cbi_tag_last(parent);
461 function cbi_bind(obj, type, callback, mode) {
462 if (!obj.addEventListener) {
463 obj.attachEvent('on' + type,
465 var e = window.event;
467 if (!e.target && e.srcElement)
468 e.target = e.srcElement;
470 return !!callback(e);
474 obj.addEventListener(type, callback, !!mode);
479 function cbi_combobox(id, values, def, man) {
480 var selid = "cbi.combobox." + id;
481 if (document.getElementById(selid)) {
485 var obj = document.getElementById(id)
486 var sel = document.createElement("select");
488 sel.className = obj.className.replace(/cbi-input-text/, 'cbi-input-select');
490 if (obj.nextSibling) {
491 obj.parentNode.insertBefore(sel, obj.nextSibling);
493 obj.parentNode.appendChild(sel);
496 var dt = obj.getAttribute('cbi_datatype');
497 var op = obj.getAttribute('cbi_optional');
500 cbi_validate_field(sel, op == 'true', dt);
502 if (!values[obj.value]) {
503 if (obj.value == "") {
504 var optdef = document.createElement("option");
506 optdef.appendChild(document.createTextNode(def));
507 sel.appendChild(optdef);
509 var opt = document.createElement("option");
510 opt.value = obj.value;
511 opt.selected = "selected";
512 opt.appendChild(document.createTextNode(obj.value));
513 sel.appendChild(opt);
517 for (var i in values) {
518 var opt = document.createElement("option");
521 if (obj.value == i) {
522 opt.selected = "selected";
525 opt.appendChild(document.createTextNode(values[i]));
526 sel.appendChild(opt);
529 var optman = document.createElement("option");
531 optman.appendChild(document.createTextNode(man));
532 sel.appendChild(optman);
534 obj.style.display = "none";
536 cbi_bind(sel, "change", function() {
537 if (sel.selectedIndex == sel.options.length - 1) {
538 obj.style.display = "inline";
539 sel.parentNode.removeChild(sel);
542 obj.value = sel.options[sel.selectedIndex].value;
552 // Retrigger validation in select
557 function cbi_combobox_init(id, values, def, man) {
558 var obj = document.getElementById(id);
559 cbi_bind(obj, "blur", function() {
560 cbi_combobox(id, values, def, man)
562 cbi_combobox(id, values, def, man);
565 function cbi_filebrowser(id, url, defpath) {
566 var field = document.getElementById(id);
567 var browser = window.open(
568 url + ( field.value || defpath || '' ) + '?field=' + id,
569 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
575 function cbi_browser_init(id, respath, url, defpath)
577 function cbi_browser_btnclick(e) {
578 cbi_filebrowser(id, url, defpath);
582 var field = document.getElementById(id);
584 var btn = document.createElement('img');
585 btn.className = 'cbi-image-button';
586 btn.src = respath + '/cbi/folder.gif';
587 field.parentNode.insertBefore(btn, field.nextSibling);
589 cbi_bind(btn, 'click', cbi_browser_btnclick);
592 function cbi_dynlist_init(name, respath, datatype, optional, url, defpath, choices)
594 var input0 = document.getElementsByName(name)[0];
595 var prefix = input0.name;
596 var parent = input0.parentNode;
597 var holder = input0.placeholder;
601 function cbi_dynlist_redraw(focus, add, del)
605 while (parent.firstChild)
607 var n = parent.firstChild;
608 var i = parseInt(n.index);
612 if (n.nodeName.toLowerCase() == 'input')
613 values.push(n.value || '');
614 else if (n.nodeName.toLowerCase() == 'select')
615 values[values.length-1] = n.options[n.selectedIndex].value;
618 parent.removeChild(n);
624 values.splice(focus, 0, '');
626 else if (values.length == 0)
632 for (var i = 0; i < values.length; i++)
634 var t = document.createElement('input');
635 t.id = prefix + '.' + (i+1);
640 t.className = 'cbi-input-text';
642 if (i == 0 && holder)
644 t.placeholder = holder;
647 var b = document.createElement('img');
648 b.src = respath + ((i+1) < values.length ? '/cbi/remove.gif' : '/cbi/add.gif');
649 b.className = 'cbi-image-button';
651 parent.appendChild(t);
652 parent.appendChild(b);
653 if (datatype == 'file')
655 cbi_browser_init(t.id, respath, url, defpath);
658 parent.appendChild(document.createElement('br'));
662 cbi_validate_field(t.id, ((i+1) == values.length) || optional, datatype);
667 cbi_combobox_init(t.id, choices[0], '', choices[1]);
670 cbi_bind(b, 'keydown', cbi_dynlist_keydown);
671 cbi_bind(b, 'keypress', cbi_dynlist_keypress);
673 if (i == focus || -i == focus)
678 cbi_bind(t, 'keydown', cbi_dynlist_keydown);
679 cbi_bind(t, 'keypress', cbi_dynlist_keypress);
685 else if (-i == focus)
689 /* force cursor to end */
696 cbi_bind(b, 'click', cbi_dynlist_btnclick);
700 function cbi_dynlist_keypress(ev)
702 ev = ev ? ev : window.event;
704 var se = ev.target ? ev.target : ev.srcElement;
706 if (se.nodeType == 3)
711 /* backspace, delete */
714 if (se.value.length == 0)
716 if (ev.preventDefault)
724 /* enter, arrow up, arrow down */
728 if (ev.preventDefault)
737 function cbi_dynlist_keydown(ev)
739 ev = ev ? ev : window.event;
741 var se = ev.target ? ev.target : ev.srcElement;
743 if (se.nodeType == 3)
746 var prev = se.previousSibling;
747 while (prev && prev.name != name)
748 prev = prev.previousSibling;
750 var next = se.nextSibling;
751 while (next && next.name != name)
752 next = next.nextSibling;
754 /* advance one further in combobox case */
755 if (next && next.nextSibling.name == name)
756 next = next.nextSibling;
760 /* backspace, delete */
763 var del = (se.nodeName.toLowerCase() == 'select')
764 ? true : (se.value.length == 0);
768 if (ev.preventDefault)
771 var focus = se.index;
775 cbi_dynlist_redraw(focus, -1, se.index);
784 cbi_dynlist_redraw(-1, se.index, -1);
805 function cbi_dynlist_btnclick(ev)
807 ev = ev ? ev : window.event;
809 var se = ev.target ? ev.target : ev.srcElement;
810 var input = se.previousSibling;
811 while (input && input.name != name) {
812 input = input.previousSibling;
815 if (se.src.indexOf('remove') > -1)
819 cbi_dynlist_keydown({
826 cbi_dynlist_keydown({
835 cbi_dynlist_redraw(NaN, -1, -1);
838 //Hijacks the CBI form to send via XHR (requires Prototype)
839 function cbi_hijack_forms(layer, win, fail, load) {
840 var forms = layer.getElementsByTagName('form');
841 for (var i=0; i<forms.length; i++) {
842 $(forms[i]).observe('submit', function(event) {
843 // Prevent the form from also submitting the regular way
847 event.element().request({
860 function cbi_t_add(section, tab) {
861 var t = document.getElementById('tab.' + section + '.' + tab);
862 var c = document.getElementById('container.' + section + '.' + tab);
865 cbi_t[section] = (cbi_t[section] || [ ]);
866 cbi_t[section][tab] = { 'tab': t, 'container': c, 'cid': c.id };
870 function cbi_t_switch(section, tab) {
871 if( cbi_t[section] && cbi_t[section][tab] ) {
872 var o = cbi_t[section][tab];
873 var h = document.getElementById('tab.' + section);
874 for( var tid in cbi_t[section] ) {
875 var o2 = cbi_t[section][tid];
876 if( o.tab.id != o2.tab.id ) {
877 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
878 o2.container.style.display = 'none';
882 o2.tab.className = o2.tab.className.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
883 o2.container.style.display = 'block';
890 function cbi_t_update() {
894 for( var sid in cbi_t )
895 for( var tid in cbi_t[sid] )
897 if( cbi_c[cbi_t[sid][tid].cid] == 0 ) {
898 cbi_t[sid][tid].tab.style.display = 'none';
900 else if( cbi_t[sid][tid].tab && cbi_t[sid][tid].tab.style.display == 'none' ) {
901 cbi_t[sid][tid].tab.style.display = '';
903 var t = cbi_t[sid][tid].tab;
904 t.className += ' cbi-tab-highlighted';
908 cbi_tag_last(cbi_t[sid][tid].container);
912 if( hl_tabs.length > 0 )
913 window.setTimeout(function() {
914 for( var i = 0; i < hl_tabs.length; i++ )
915 hl_tabs[i].className = hl_tabs[i].className.replace(/ cbi-tab-highlighted/g, '');
922 function cbi_validate_form(form, errmsg)
924 /* if triggered by a section removal or addition, don't validate */
925 if( form.cbi_state == 'add-section' || form.cbi_state == 'del-section' )
928 if( form.cbi_validators )
930 for( var i = 0; i < form.cbi_validators.length; i++ )
932 var validator = form.cbi_validators[i];
933 if( !validator() && errmsg )
944 function cbi_validate_reset(form)
947 function() { cbi_validate_form(form, null) }, 100
953 function cbi_validate_compile(code)
962 for (var i = 0; i < code.length; i++)
970 switch (code.charCodeAt(i))
982 var label = code.substring(pos, i);
983 label = label.replace(/\\(.)/g, '$1');
984 label = label.replace(/^[ \t]+/g, '');
985 label = label.replace(/[ \t]+$/g, '');
987 if (label && !isNaN(label))
989 stack.push(parseFloat(label));
991 else if (label.match(/^(['"]).*\1$/))
993 stack.push(label.replace(/^(['"])(.*)\1$/, '$2'));
995 else if (typeof cbi_validators[label] == 'function')
997 stack.push(cbi_validators[label]);
1002 throw "Syntax error, unhandled token '"+label+"'";
1007 depth += (code.charCodeAt(i) == 40);
1013 if (typeof stack[stack.length-2] != 'function')
1014 throw "Syntax error, argument list follows non-function";
1016 stack[stack.length-1] =
1017 arguments.callee(code.substring(pos, i));
1028 function cbi_validate_field(cbid, optional, type)
1030 var field = (typeof cbid == "string") ? document.getElementById(cbid) : cbid;
1031 var vstack; try { vstack = cbi_validate_compile(type); } catch(e) { };
1033 if (field && vstack && typeof vstack[0] == "function")
1035 var validator = function()
1040 field.className = field.className.replace(/ cbi-input-invalid/g, '');
1043 var value = (field.options && field.options.selectedIndex > -1)
1044 ? field.options[field.options.selectedIndex].value : field.value;
1046 if (!(((value.length == 0) && optional) || vstack[0].apply(value, vstack[1])))
1049 field.className += ' cbi-input-invalid';
1057 if( ! field.form.cbi_validators )
1058 field.form.cbi_validators = [ ];
1060 field.form.cbi_validators.push(validator);
1062 cbi_bind(field, "blur", validator);
1063 cbi_bind(field, "keyup", validator);
1065 if (field.nodeName == 'SELECT')
1067 cbi_bind(field, "change", validator);
1068 cbi_bind(field, "click", validator);
1071 field.setAttribute("cbi_validate", validator);
1072 field.setAttribute("cbi_datatype", type);
1073 field.setAttribute("cbi_optional", (!!optional).toString());
1077 var fcbox = document.getElementById('cbi.combobox.' + field.id);
1079 cbi_validate_field(fcbox, optional, type);
1083 function cbi_row_swap(elem, up, store)
1085 var tr = elem.parentNode;
1086 while (tr && tr.nodeName.toLowerCase() != 'tr')
1092 var table = tr.parentNode;
1093 while (table && table.nodeName.toLowerCase() != 'table')
1094 table = table.parentNode;
1100 var e = up ? table.rows.length : table.rows.length - 1;
1102 for (var idx = s; idx < e; idx++)
1104 if (table.rows[idx] == tr)
1107 tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]);
1109 tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]);
1116 for (idx = 2; idx < table.rows.length; idx++)
1118 table.rows[idx].className = table.rows[idx].className.replace(
1119 /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx % 2))
1122 if (table.rows[idx].id && table.rows[idx].id.match(/-([^\-]+)$/) )
1123 ids.push(RegExp.$1);
1126 var input = document.getElementById(store);
1128 input.value = ids.join(' ');
1133 function cbi_tag_last(container)
1137 for (var i = 0; i < container.childNodes.length; i++)
1139 var c = container.childNodes[i];
1140 if (c.nodeType == 1 && c.nodeName.toLowerCase() == 'div')
1142 c.className = c.className.replace(/ cbi-value-last$/, '');
1149 last.className += ' cbi-value-last';
1153 String.prototype.serialize = function()
1170 for( var i = 0; i < o.length; i++ )
1171 s += (s ? ', ' : '') + String.serialize(o[i]);
1173 return '[ ' + s + ' ]';
1182 s += (s ? ', ' : '') + k + ': ' + String.serialize(o[k]);
1184 return '{ ' + s + ' }';
1191 if( o.match(/[^a-zA-Z0-9_,.: -]/) )
1192 return 'decodeURIComponent("' + encodeURIComponent(o) + '")';
1196 return '"' + o + '"';
1201 return o.toString();
1205 String.prototype.format = function()
1210 var html_esc = [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1211 var quot_esc = [/"/g, '"', /'/g, '''];
1213 function esc(s, r) {
1214 for( var i = 0; i < r.length; i += 2 )
1215 s = s.replace(r[i], r[i+1]);
1221 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/;
1222 var a = b = [], numSubstitutions = 0, numMatches = 0;
1224 while( a = re.exec(str) )
1227 var leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5];
1228 var pPrecision = a[6], pType = a[7];
1238 if (numSubstitutions < arguments.length)
1240 var param = arguments[numSubstitutions++];
1243 if (pPad && pPad.substr(0,1) == "'")
1244 pad = leftpart.substr(1,1);
1248 var justifyRight = true;
1249 if (pJustify && pJustify === "-")
1250 justifyRight = false;
1254 minLength = parseInt(pMinLength);
1257 if (pPrecision && pType == 'f')
1258 precision = parseInt(pPrecision.substring(1));
1265 subst = (parseInt(param) || 0).toString(2);
1269 subst = String.fromCharCode(parseInt(param) || 0);
1273 subst = (parseInt(param) || 0);
1277 subst = Math.abs(parseInt(param) || 0);
1281 subst = (precision > -1)
1282 ? ((parseFloat(param) || 0.0)).toFixed(precision)
1283 : (parseFloat(param) || 0.0);
1287 subst = (parseInt(param) || 0).toString(8);
1295 subst = ('' + (parseInt(param) || 0).toString(16)).toLowerCase();
1299 subst = ('' + (parseInt(param) || 0).toString(16)).toUpperCase();
1303 subst = esc(param, html_esc);
1307 subst = esc(param, quot_esc);
1311 subst = String.serialize(param);
1318 var ts = (param || 0);
1321 tm = Math.floor(ts / 60);
1326 th = Math.floor(tm / 60);
1331 td = Math.floor(th / 24);
1336 ? String.format('%dd %dh %dm %ds', td, th, tm, ts)
1337 : String.format('%dh %dm %ds', th, tm, ts);
1342 var mf = pMinLength ? parseInt(pMinLength) : 1000;
1343 var pr = pPrecision ? Math.floor(10*parseFloat('0'+pPrecision)) : 2;
1346 var val = parseFloat(param || 0);
1347 var units = [ '', 'K', 'M', 'G', 'T', 'P', 'E' ];
1349 for (i = 0; (i < units.length) && (val > mf); i++)
1352 subst = val.toFixed(pr) + ' ' + units[i];
1358 out += leftpart + subst;
1359 str = str.substr(m.length);
1365 String.prototype.nobr = function()
1367 return this.replace(/[\s\n]+/g, ' ');
1370 String.serialize = function()
1373 for (var i = 1; i < arguments.length; i++)
1374 a.push(arguments[i]);
1375 return ''.serialize.apply(arguments[0], a);
1378 String.format = function()
1381 for (var i = 1; i < arguments.length; i++)
1382 a.push(arguments[i]);
1383 return ''.format.apply(arguments[0], a);
1386 String.nobr = function()
1389 for (var i = 1; i < arguments.length; i++)
1390 a.push(arguments[i]);
1391 return ''.nobr.apply(arguments[0], a);