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
16 var cbi_strings
= { path
: {}, label
: {} };
19 return (/^-?\d+$/.test(x
) ? +x
: NaN
);
23 return (/^-?\d+(?:\.\d+)?$/.test(x
) ? +x
: NaN
);
27 if (!x
.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/))
30 if (RegExp
.$1 > 255 || RegExp
.$2 > 255 || RegExp
.$3 > 255 || RegExp
.$4 > 255)
33 return [ +RegExp
.$1, +RegExp
.$2, +RegExp
.$3, +RegExp
.$4 ];
37 if (x
.match(/^([a-fA-F0-9:]+):(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/)) {
38 var v6
= RegExp
.$1, v4
= IPv4(RegExp
.$2);
43 x
= v6
+ ':' + (v4
[0] * 256 + v4
[1]).toString(16)
44 + ':' + (v4
[2] * 256 + v4
[3]).toString(16);
47 if (!x
.match(/^[a-fA-F0-9:]+$/))
50 var prefix_suffix
= x
.split(/::/);
52 if (prefix_suffix
.length
> 2)
55 var prefix
= (prefix_suffix
[0] || '0').split(/:/);
56 var suffix
= prefix_suffix
.length
> 1 ? (prefix_suffix
[1] || '0').split(/:/) : [];
58 if (suffix
.length
? (prefix
.length
+ suffix
.length
> 7) : (prefix
.length
> 8))
64 for (i
= 0, word
= parseInt(prefix
[0], 16); i
< prefix
.length
; word
= parseInt(prefix
[++i
], 16))
65 if (prefix
[i
].length
<= 4 && !isNaN(word
) && word
<= 0xFFFF)
70 for (i
= 0; i
< (8 - prefix
.length
- suffix
.length
); i
++)
73 for (i
= 0, word
= parseInt(suffix
[0], 16); i
< suffix
.length
; word
= parseInt(suffix
[++i
], 16))
74 if (suffix
[i
].length
<= 4 && !isNaN(word
) && word
<= 0xFFFF)
82 var cbi_validators
= {
89 'uinteger': function()
91 return (Int(this) >= 0);
101 return (Dec(this) >= 0);
106 return cbi_validators
.ip4addr
.apply(this) ||
107 cbi_validators
.ip6addr
.apply(this);
110 'ip4addr': function()
112 var m
= this.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?:\/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|\/(\d{1,2}))?$/);
113 return !!(m
&& IPv4(m
[1]) && (m
[2] ? IPv4(m
[2]) : (m
[3] ? cbi_validators
.ip4prefix
.apply(m
[3]) : true)));
116 'ip6addr': function()
118 var m
= this.match(/^([0-9a-fA-F:.]+)(?:\/(\d{1,3}))?$/);
119 return !!(m
&& IPv6(m
[1]) && (m
[2] ? cbi_validators
.ip6prefix
.apply(m
[2]) : true));
122 'ip4prefix': function()
124 return !isNaN(this) && this >= 0 && this <= 32;
127 'ip6prefix': function()
129 return !isNaN(this) && this >= 0 && this <= 128;
134 return cbi_validators
.cidr4
.apply(this) ||
135 cbi_validators
.cidr6
.apply(this);
140 var m
= this.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/(\d{1,2})$/);
141 return !!(m
&& IPv4(m
[1]) && cbi_validators
.ip4prefix
.apply(m
[2]));
146 var m
= this.match(/^([0-9a-fA-F:.]+)\/(\d{1,3})$/);
147 return !!(m
&& IPv6(m
[1]) && cbi_validators
.ip6prefix
.apply(m
[2]));
152 var m
= this.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
153 return !!(m
&& IPv4(m
[1]) && IPv4(m
[2]));
158 var m
= this.match(/^([0-9a-fA-F:.]+)\/([0-9a-fA-F:.]+)$/);
159 return !!(m
&& IPv6(m
[1]) && IPv6(m
[2]));
162 'ip6hostid': function()
164 if (this == "eui64" || this == "random")
168 return !(!v6
|| v6
[0] || v6
[1] || v6
[2] || v6
[3]);
173 return cbi_validators
.ipmask4
.apply(this) ||
174 cbi_validators
.ipmask6
.apply(this);
177 'ipmask4': function()
179 return cbi_validators
.cidr4
.apply(this) ||
180 cbi_validators
.ipnet4
.apply(this) ||
181 cbi_validators
.ip4addr
.apply(this);
184 'ipmask6': function()
186 return cbi_validators
.cidr6
.apply(this) ||
187 cbi_validators
.ipnet6
.apply(this) ||
188 cbi_validators
.ip6addr
.apply(this);
194 return (p
>= 0 && p
<= 65535);
197 'portrange': function()
199 if (this.match(/^(\d+)-(\d+)$/))
203 return (p1
<= p2
&& p2
<= 65535);
206 return cbi_validators
.port
.apply(this);
209 'macaddr': function()
211 return (this.match(/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/) != null);
214 'host': function(ipv4only
)
216 return cbi_validators
.hostname
.apply(this) ||
217 ((ipv4only
!= 1) && cbi_validators
.ipaddr
.apply(this)) ||
218 ((ipv4only
== 1) && cbi_validators
.ip4addr
.apply(this));
221 'hostname': function(strict
)
223 if (this.length
<= 253)
224 return (this.match(/^[a-zA-Z0-9_]+$/) != null ||
225 (this.match(/^[a-zA-Z0-9_][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$/) &&
226 this.match(/[^0-9.]/))) &&
227 (!strict
|| !this.match(/^_/));
232 'network': function()
234 return cbi_validators
.uciname
.apply(this) ||
235 cbi_validators
.host
.apply(this);
238 'hostport': function(ipv4only
)
240 var hp
= this.split(/:/);
243 return (cbi_validators
.host
.apply(hp
[0], ipv4only
) &&
244 cbi_validators
.port
.apply(hp
[1]));
249 'ip4addrport': function()
251 var hp
= this.split(/:/);
254 return (cbi_validators
.ipaddr
.apply(hp
[0]) &&
255 cbi_validators
.port
.apply(hp
[1]));
259 'ipaddrport': function(bracket
)
261 if (this.match(/^([^\[\]:]+):([^:]+)$/)) {
264 return (cbi_validators
.ip4addr
.apply(addr
) &&
265 cbi_validators
.port
.apply(port
));
266 } else if ((bracket
== 1) && (this.match(/^\[(.+)\]:([^:]+)$/))) {
269 return (cbi_validators
.ip6addr
.apply(addr
) &&
270 cbi_validators
.port
.apply(port
));
271 } else if ((bracket
!= 1) && (this.match(/^([^\[\]]+):([^:]+)$/))) {
274 return (cbi_validators
.ip6addr
.apply(addr
) &&
275 cbi_validators
.port
.apply(port
));
286 return (v
.match(/^[a-fA-F0-9]{64}$/) != null);
288 return (v
.length
>= 8) && (v
.length
<= 63);
295 if ( v
.substr(0,2) == 's:' )
298 if( (v
.length
== 10) || (v
.length
== 26) )
299 return (v
.match(/^[a-fA-F0-9]{10,26}$/) != null);
301 return (v
.length
== 5) || (v
.length
== 13);
304 'uciname': function()
306 return (this.match(/^[a-zA-Z0-9_]+$/) != null);
309 'range': function(min
, max
)
312 return (val
>= +min
&& val
<= +max
);
317 return (Dec(this) >= +min
);
322 return (Dec(this) <= +max
);
325 'rangelength': function(min
, max
)
328 return ((val
.length
>= +min
) && (val
.length
<= +max
));
331 'minlength': function(min
)
333 return ((''+this).length
>= +min
);
336 'maxlength': function(max
)
338 return ((''+this).length
<= +max
);
343 for (var i
= 0; i
< arguments
.length
; i
+= 2)
345 if (typeof arguments
[i
] != 'function')
347 if (arguments
[i
] == this)
351 else if (arguments
[i
].apply(this, arguments
[i
+1]))
361 for (var i
= 0; i
< arguments
.length
; i
+= 2)
363 if (typeof arguments
[i
] != 'function')
365 if (arguments
[i
] != this)
369 else if (!arguments
[i
].apply(this, arguments
[i
+1]))
379 return cbi_validators
.or
.apply(
380 this.replace(/^[ \t]*![ \t]*/, ''), arguments
);
383 'list': function(subvalidator
, subargs
)
385 if (typeof subvalidator
!= 'function')
388 var tokens
= this.match(/[^ \t]+/g);
389 for (var i
= 0; i
< tokens
.length
; i
++)
390 if (!subvalidator
.apply(tokens
[i
], subargs
))
395 'phonedigit': function()
397 return (this.match(/^[0-9\*#!\.]+$/) != null);
399 'timehhmmss': function()
401 return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null);
403 'dateyyyymmdd': function()
408 if (this.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)) {
409 var year
= RegExp
.$1;
410 var month
= RegExp
.$2;
413 var days_in_month
= [ 31, 28, 31, 30, 31, 30, 31, 31, 30 , 31, 30, 31 ];
414 function is_leap_year(year
) {
415 return ((year
% 4) == 0) && ((year
% 100) != 0) || ((year
% 400) == 0);
417 function get_days_in_month(month
, year
) {
418 if ((month
== 2) && is_leap_year(year
)) {
421 return days_in_month
[month
];
424 /* Firewall rules in the past don't make sense */
428 if ((month
<= 0) || (month
> 12)) {
431 if ((day
<= 0) || (day
> get_days_in_month(month
, year
))) {
443 function cbi_d_add(field
, dep
, index
) {
444 var obj
= (typeof(field
) === 'string') ? document
.getElementById(field
) : field
;
447 for (var i
=0; i
<cbi_d
.length
; i
++) {
448 if (cbi_d
[i
].id
== obj
.id
) {
457 "parent": obj
.parentNode
.id
,
461 cbi_d
.unshift(entry
);
467 function cbi_d_checkvalue(target
, ref
) {
469 query
= 'input[id="'+target
+'"], input[name="'+target
+'"], ' +
470 'select[id="'+target
+'"], select[name="'+target
+'"]';
472 document
.querySelectorAll(query
).forEach(function(i
) {
473 if (value
=== null && ((i
.type
!== 'radio' && i
.type
!== 'checkbox') || i
.checked
=== true))
477 return (((value
!== null) ? value
: "") == ref
);
480 function cbi_d_check(deps
) {
483 for (var i
=0; i
<deps
.length
; i
++) {
486 for (var j
in deps
[i
]) {
487 if (j
== "!reverse") {
489 } else if (j
== "!default") {
493 istat
= (istat
&& cbi_d_checkvalue(j
, deps
[i
][j
]))
497 if (istat
^ reverse
) {
504 function cbi_d_update() {
506 for (var i
=0; i
<cbi_d
.length
; i
++) {
507 var entry
= cbi_d
[i
];
508 var node
= document
.getElementById(entry
.id
);
509 var parent
= document
.getElementById(entry
.parent
);
511 if (node
&& node
.parentNode
&& !cbi_d_check(entry
.deps
)) {
512 node
.parentNode
.removeChild(node
);
514 } else if (parent
&& (!node
|| !node
.parentNode
) && cbi_d_check(entry
.deps
)) {
515 var next
= undefined;
517 for (next
= parent
.firstChild
; next
; next
= next
.nextSibling
) {
518 if (next
.getAttribute
&& parseInt(next
.getAttribute('data-index'), 10) > entry
.index
) {
524 parent
.appendChild(entry
.node
);
526 parent
.insertBefore(entry
.node
, next
);
532 // hide optionals widget if no choices remaining
533 if (parent
&& parent
.parentNode
&& parent
.getAttribute('data-optionals'))
534 parent
.parentNode
.style
.display
= (parent
.options
.length
<= 1) ? 'none' : '';
537 if (entry
&& entry
.parent
) {
539 cbi_tag_last(parent
);
547 function cbi_init() {
550 nodes
= document
.querySelectorAll('[data-strings]');
552 for (var i
= 0, node
; (node
= nodes
[i
]) !== undefined; i
++) {
553 var str
= JSON
.parse(node
.getAttribute('data-strings'));
554 for (var key
in str
) {
555 for (var key2
in str
[key
]) {
556 var dst
= cbi_strings
[key
] || (cbi_strings
[key
] = { });
557 dst
[key2
] = str
[key
][key2
];
562 nodes
= document
.querySelectorAll('[data-depends]');
564 for (var i
= 0, node
; (node
= nodes
[i
]) !== undefined; i
++) {
565 var index
= parseInt(node
.getAttribute('data-index'), 10);
566 var depends
= JSON
.parse(node
.getAttribute('data-depends'));
567 if (!isNaN(index
) && depends
.length
> 0) {
568 for (var alt
= 0; alt
< depends
.length
; alt
++) {
569 cbi_d_add(node
, depends
[alt
], index
);
574 nodes
= document
.querySelectorAll('[data-update]');
576 for (var i
= 0, node
; (node
= nodes
[i
]) !== undefined; i
++) {
577 var events
= node
.getAttribute('data-update').split(' ');
578 for (var j
= 0, event
; (event
= events
[j
]) !== undefined; j
++) {
579 cbi_bind(node
, event
, cbi_d_update
);
583 nodes
= document
.querySelectorAll('[data-choices]');
585 for (var i
= 0, node
; (node
= nodes
[i
]) !== undefined; i
++) {
586 var choices
= JSON
.parse(node
.getAttribute('data-choices'));
589 for (var j
= 0; j
< choices
[0].length
; j
++)
590 options
[choices
[0][j
]] = choices
[1][j
];
592 var def
= (node
.getAttribute('data-optional') === 'true')
593 ? node
.placeholder
|| '' : null;
595 cbi_combobox_init(node
, options
, def
,
596 node
.getAttribute('data-manual'));
599 nodes
= document
.querySelectorAll('[data-dynlist]');
601 for (var i
= 0, node
; (node
= nodes
[i
]) !== undefined; i
++) {
602 var choices
= JSON
.parse(node
.getAttribute('data-dynlist'));
605 if (choices
[0] && choices
[0].length
) {
608 for (var j
= 0; j
< choices
[0].length
; j
++)
609 options
[choices
[0][j
]] = choices
[1][j
];
612 cbi_dynlist_init(node
, choices
[2], choices
[3], options
);
615 nodes
= document
.querySelectorAll('[data-type]');
617 for (var i
= 0, node
; (node
= nodes
[i
]) !== undefined; i
++) {
618 cbi_validate_field(node
, node
.getAttribute('data-optional') === 'true',
619 node
.getAttribute('data-type'));
622 document
.querySelectorAll('.cbi-dropdown').forEach(function(s
) {
623 cbi_dropdown_init(s
);
629 function cbi_bind(obj
, type
, callback
, mode
) {
630 if (!obj
.addEventListener
) {
631 obj
.attachEvent('on' + type
,
633 var e
= window
.event
;
635 if (!e
.target
&& e
.srcElement
)
636 e
.target
= e
.srcElement
;
638 return !!callback(e
);
642 obj
.addEventListener(type
, callback
, !!mode
);
647 function cbi_combobox(id
, values
, def
, man
, focus
) {
648 var selid
= "cbi.combobox." + id
;
649 if (document
.getElementById(selid
)) {
653 var obj
= document
.getElementById(id
)
654 var sel
= document
.createElement("select");
656 sel
.index
= obj
.index
;
657 sel
.className
= obj
.className
.replace(/cbi-input-text/, 'cbi-input-select');
659 if (obj
.nextSibling
) {
660 obj
.parentNode
.insertBefore(sel
, obj
.nextSibling
);
662 obj
.parentNode
.appendChild(sel
);
665 var dt
= obj
.getAttribute('cbi_datatype');
666 var op
= obj
.getAttribute('cbi_optional');
668 if (!values
[obj
.value
]) {
669 if (obj
.value
== "") {
670 var optdef
= document
.createElement("option");
672 optdef
.appendChild(document
.createTextNode(typeof(def
) === 'string' ? def
: cbi_strings
.label
.choose
));
673 sel
.appendChild(optdef
);
675 var opt
= document
.createElement("option");
676 opt
.value
= obj
.value
;
677 opt
.selected
= "selected";
678 opt
.appendChild(document
.createTextNode(obj
.value
));
679 sel
.appendChild(opt
);
683 for (var i
in values
) {
684 var opt
= document
.createElement("option");
687 if (obj
.value
== i
) {
688 opt
.selected
= "selected";
691 opt
.appendChild(document
.createTextNode(values
[i
]));
692 sel
.appendChild(opt
);
695 var optman
= document
.createElement("option");
697 optman
.appendChild(document
.createTextNode(typeof(man
) === 'string' ? man
: cbi_strings
.label
.custom
));
698 sel
.appendChild(optman
);
700 obj
.style
.display
= "none";
703 cbi_validate_field(sel
, op
== 'true', dt
);
705 cbi_bind(sel
, "change", function() {
706 if (sel
.selectedIndex
== sel
.options
.length
- 1) {
707 obj
.style
.display
= "inline";
709 sel
.parentNode
.removeChild(sel
);
712 obj
.value
= sel
.options
[sel
.selectedIndex
].value
;
722 // Retrigger validation in select
729 function cbi_combobox_init(id
, values
, def
, man
) {
730 var obj
= (typeof(id
) === 'string') ? document
.getElementById(id
) : id
;
731 cbi_bind(obj
, "blur", function() {
732 cbi_combobox(obj
.id
, values
, def
, man
, true);
734 cbi_combobox(obj
.id
, values
, def
, man
, false);
737 function cbi_filebrowser(id
, defpath
) {
738 var field
= document
.getElementById(id
);
739 var browser
= window
.open(
740 cbi_strings
.path
.browser
+ ( field
.value
|| defpath
|| '' ) + '?field=' + id
,
741 "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
747 function cbi_browser_init(id
, resource
, defpath
)
749 function cbi_browser_btnclick(e
) {
750 cbi_filebrowser(id
, defpath
);
754 var field
= document
.getElementById(id
);
756 var btn
= document
.createElement('img');
757 btn
.className
= 'cbi-image-button';
758 btn
.src
= (resource
|| cbi_strings
.path
.resource
) + '/cbi/folder.gif';
759 field
.parentNode
.insertBefore(btn
, field
.nextSibling
);
761 cbi_bind(btn
, 'click', cbi_browser_btnclick
);
764 function cbi_dynlist_init(parent
, datatype
, optional
, choices
)
766 var prefix
= parent
.getAttribute('data-prefix');
767 var holder
= parent
.getAttribute('data-placeholder');
771 function cbi_dynlist_redraw(focus
, add
, del
)
775 while (parent
.firstChild
)
777 var n
= parent
.firstChild
;
782 if (n
.nodeName
.toLowerCase() == 'input')
783 values
.push(n
.value
|| '');
784 else if (n
.nodeName
.toLowerCase() == 'select')
785 values
[values
.length
-1] = n
.options
[n
.selectedIndex
].value
;
788 parent
.removeChild(n
);
794 values
.splice(focus
, 0, '');
796 else if (values
.length
== 0)
802 for (var i
= 0; i
< values
.length
; i
++)
804 var t
= document
.createElement('input');
805 t
.id
= prefix
+ '.' + (i
+1);
810 t
.className
= 'cbi-input-text';
812 if (i
== 0 && holder
)
814 t
.placeholder
= holder
;
817 var b
= document
.createElement('img');
818 b
.src
= cbi_strings
.path
.resource
+ ((i
+1) < values
.length
? '/cbi/remove.gif' : '/cbi/add.gif');
819 b
.className
= 'cbi-image-button';
821 parent
.appendChild(t
);
822 parent
.appendChild(b
);
823 if (datatype
== 'file')
825 cbi_browser_init(t
.id
, null, parent
.getAttribute('data-browser-path'));
828 parent
.appendChild(document
.createElement('br'));
832 cbi_validate_field(t
.id
, ((i
+1) == values
.length
) || optional
, datatype
);
837 cbi_combobox_init(t
.id
, choices
, '', cbi_strings
.label
.custom
);
840 cbi_bind(b
, 'keydown', cbi_dynlist_keydown
);
841 cbi_bind(b
, 'keypress', cbi_dynlist_keypress
);
843 if (i
== focus
|| -i
== focus
)
848 cbi_bind(t
, 'keydown', cbi_dynlist_keydown
);
849 cbi_bind(t
, 'keypress', cbi_dynlist_keypress
);
855 else if (-i
== focus
)
859 /* force cursor to end */
866 cbi_bind(b
, 'click', cbi_dynlist_btnclick
);
870 function cbi_dynlist_keypress(ev
)
872 ev
= ev
? ev
: window
.event
;
874 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
876 if (se
.nodeType
== 3)
881 /* backspace, delete */
884 if (se
.value
.length
== 0)
886 if (ev
.preventDefault
)
894 /* enter, arrow up, arrow down */
898 if (ev
.preventDefault
)
907 function cbi_dynlist_keydown(ev
)
909 ev
= ev
? ev
: window
.event
;
911 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
913 if (se
.nodeType
== 3)
916 var prev
= se
.previousSibling
;
917 while (prev
&& prev
.name
!= prefix
)
918 prev
= prev
.previousSibling
;
920 var next
= se
.nextSibling
;
921 while (next
&& next
.name
!= prefix
)
922 next
= next
.nextSibling
;
924 /* advance one further in combobox case */
925 if (next
&& next
.nextSibling
.name
== prefix
)
926 next
= next
.nextSibling
;
930 /* backspace, delete */
933 var del
= (se
.nodeName
.toLowerCase() == 'select')
934 ? true : (se
.value
.length
== 0);
938 if (ev
.preventDefault
)
941 var focus
= se
.index
;
945 cbi_dynlist_redraw(focus
, -1, se
.index
);
954 cbi_dynlist_redraw(-1, se
.index
, -1);
975 function cbi_dynlist_btnclick(ev
)
977 ev
= ev
? ev
: window
.event
;
979 var se
= ev
.target
? ev
.target
: ev
.srcElement
;
980 var input
= se
.previousSibling
;
981 while (input
&& input
.name
!= prefix
) {
982 input
= input
.previousSibling
;
985 if (se
.src
.indexOf('remove') > -1)
989 cbi_dynlist_keydown({
996 cbi_dynlist_keydown({
1005 cbi_dynlist_redraw(NaN
, -1, -1);
1009 function cbi_t_add(section
, tab
) {
1010 var t
= document
.getElementById('tab.' + section
+ '.' + tab
);
1011 var c
= document
.getElementById('container.' + section
+ '.' + tab
);
1014 cbi_t
[section
] = (cbi_t
[section
] || [ ]);
1015 cbi_t
[section
][tab
] = { 'tab': t
, 'container': c
, 'cid': c
.id
};
1019 function cbi_t_switch(section
, tab
) {
1020 if( cbi_t
[section
] && cbi_t
[section
][tab
] ) {
1021 var o
= cbi_t
[section
][tab
];
1022 var h
= document
.getElementById('tab.' + section
);
1023 for( var tid
in cbi_t
[section
] ) {
1024 var o2
= cbi_t
[section
][tid
];
1025 if( o
.tab
.id
!= o2
.tab
.id
) {
1026 o2
.tab
.className
= o2
.tab
.className
.replace(/(^| )cbi-tab( |$)/, " cbi-tab-disabled ");
1027 o2
.container
.style
.display
= 'none';
1030 if(h
) h
.value
= tab
;
1031 o2
.tab
.className
= o2
.tab
.className
.replace(/(^| )cbi-tab-disabled( |$)/, " cbi-tab ");
1032 o2
.container
.style
.display
= 'block';
1039 function cbi_t_update() {
1041 var updated
= false;
1043 for( var sid
in cbi_t
)
1044 for( var tid
in cbi_t
[sid
] )
1046 var t
= cbi_t
[sid
][tid
].tab
;
1047 var c
= cbi_t
[sid
][tid
].container
;
1049 if (!c
.firstElementChild
) {
1050 t
.style
.display
= 'none';
1052 else if (t
.style
.display
== 'none') {
1053 t
.style
.display
= '';
1054 t
.className
+= ' cbi-tab-highlighted';
1062 if (hl_tabs
.length
> 0)
1063 window
.setTimeout(function() {
1064 for( var i
= 0; i
< hl_tabs
.length
; i
++ )
1065 hl_tabs
[i
].className
= hl_tabs
[i
].className
.replace(/ cbi
-tab
-highlighted
/g
, '');
1072 function cbi_validate_form(form
, errmsg
)
1074 /* if triggered by a section removal or addition, don't validate */
1075 if( form
.cbi_state
== 'add-section' || form
.cbi_state
== 'del-section' )
1078 if( form
.cbi_validators
)
1080 for( var i
= 0; i
< form
.cbi_validators
.length
; i
++ )
1082 var validator
= form
.cbi_validators
[i
];
1083 if( !validator() && errmsg
)
1094 function cbi_validate_reset(form
)
1097 function() { cbi_validate_form(form
, null) }, 100
1103 function cbi_validate_compile(code
)
1112 for (var i
= 0; i
< code
.length
; i
++)
1120 switch (code
.charCodeAt(i
))
1132 var label
= code
.substring(pos
, i
);
1133 label
= label
.replace(/\\(.)/g, '$1');
1134 label
= label
.replace(/^[ \t]+/g, '');
1135 label
= label
.replace(/[ \t]+$/g, '');
1137 if (label
&& !isNaN(label
))
1139 stack
.push(parseFloat(label
));
1141 else if (label
.match(/^(['"]).*\1$/))
1143 stack
.push(label
.replace(/^(['"])(.*)\1$/, '$2'));
1145 else if (typeof cbi_validators
[label
] == 'function')
1147 stack
.push(cbi_validators
[label
]);
1152 throw "Syntax error, unhandled token '"+label
+"'";
1157 depth
+= (code
.charCodeAt(i
) == 40);
1163 if (typeof stack
[stack
.length
-2] != 'function')
1164 throw "Syntax error, argument list follows non-function";
1166 stack
[stack
.length
-1] =
1167 arguments
.callee(code
.substring(pos
, i
));
1178 function cbi_validate_field(cbid
, optional
, type
)
1180 var field
= (typeof cbid
== "string") ? document
.getElementById(cbid
) : cbid
;
1181 var vstack
; try { vstack
= cbi_validate_compile(type
); } catch(e
) { };
1183 if (field
&& vstack
&& typeof vstack
[0] == "function")
1185 var validator = function()
1190 field
.className
= field
.className
.replace(/ cbi
-input
-invalid
/g
, '');
1193 var value
= (field
.options
&& field
.options
.selectedIndex
> -1)
1194 ? field
.options
[field
.options
.selectedIndex
].value
: field
.value
;
1196 if (!(((value
.length
== 0) && optional
) || vstack
[0].apply(value
, vstack
[1])))
1199 field
.className
+= ' cbi-input-invalid';
1207 if( ! field
.form
.cbi_validators
)
1208 field
.form
.cbi_validators
= [ ];
1210 field
.form
.cbi_validators
.push(validator
);
1212 cbi_bind(field
, "blur", validator
);
1213 cbi_bind(field
, "keyup", validator
);
1215 if (field
.nodeName
== 'SELECT')
1217 cbi_bind(field
, "change", validator
);
1218 cbi_bind(field
, "click", validator
);
1221 field
.setAttribute("cbi_validate", validator
);
1222 field
.setAttribute("cbi_datatype", type
);
1223 field
.setAttribute("cbi_optional", (!!optional
).toString());
1227 var fcbox
= document
.getElementById('cbi.combobox.' + field
.id
);
1229 cbi_validate_field(fcbox
, optional
, type
);
1233 function cbi_row_swap(elem
, up
, store
)
1235 var tr
= elem
.parentNode
;
1237 while (tr
&& !tr
.classList
.contains('cbi-section-table-row'))
1244 var prev
= tr
.previousElementSibling
;
1246 if (prev
&& prev
.classList
.contains('cbi-section-table-row'))
1247 tr
.parentNode
.insertBefore(tr
, prev
);
1252 var next
= tr
.nextElementSibling
? tr
.nextElementSibling
.nextElementSibling
: null;
1254 if (next
&& next
.classList
.contains('cbi-section-table-row'))
1255 tr
.parentNode
.insertBefore(tr
, next
);
1257 tr
.parentNode
.appendChild(tr
);
1264 for (var i
= 0, n
= 0; i
< tr
.parentNode
.childNodes
.length
; i
++) {
1265 var node
= tr
.parentNode
.childNodes
[i
];
1266 if (node
.classList
&& node
.classList
.contains('cbi-section-table-row')) {
1267 node
.classList
.remove('cbi-rowstyle-1');
1268 node
.classList
.remove('cbi-rowstyle-2');
1269 node
.classList
.add((n
++ % 2) ? 'cbi-rowstyle-2' : 'cbi-rowstyle-1');
1271 if (/-([^\-]+)$/.test(node
.id
))
1272 ids
.push(RegExp
.$1);
1276 var input
= document
.getElementById(store
);
1278 input
.value
= ids
.join(' ');
1283 function cbi_tag_last(container
)
1287 for (var i
= 0; i
< container
.childNodes
.length
; i
++)
1289 var c
= container
.childNodes
[i
];
1290 if (c
.nodeType
== 1 && c
.nodeName
.toLowerCase() == 'div')
1292 c
.className
= c
.className
.replace(/ cbi
-value
-last
$/, '');
1299 last
.className
+= ' cbi-value-last';
1303 String
.prototype.format = function()
1308 var html_esc
= [/&/g, '&', /"/g, '"', /'/g, ''', /</g, '<', />/g, '>'];
1309 var quot_esc = [/"/g
, '"', /'/g, '''];
1311 function esc(s, r) {
1312 if (typeof(s) !== 'string
' && !(s instanceof String))
1315 for( var i = 0; i < r.length; i += 2 )
1316 s = s.replace(r[i], r[i+1]);
1322 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d
+)?(\.\d
+)?(%|b
|c
|d
|u
|f
|o
|s
|x
|X
|q
|h
|j
|t
|m
))/;
1323 var a
= b
= [], numSubstitutions
= 0, numMatches
= 0;
1325 while (a
= re
.exec(str
))
1328 var leftpart
= a
[2], pPad
= a
[3], pJustify
= a
[4], pMinLength
= a
[5];
1329 var pPrecision
= a
[6], pType
= a
[7];
1339 if (numSubstitutions
< arguments
.length
)
1341 var param
= arguments
[numSubstitutions
++];
1344 if (pPad
&& pPad
.substr(0,1) == "'")
1345 pad
= leftpart
.substr(1,1);
1351 var justifyRight
= true;
1352 if (pJustify
&& pJustify
=== "-")
1353 justifyRight
= false;
1357 minLength
= +pMinLength
;
1360 if (pPrecision
&& pType
== 'f')
1361 precision
= +pPrecision
.substring(1);
1368 subst
= (+param
|| 0).toString(2);
1372 subst
= String
.fromCharCode(+param
|| 0);
1376 subst
= ~~(+param
|| 0);
1380 subst
= ~~Math
.abs(+param
|| 0);
1384 subst
= (precision
> -1)
1385 ? ((+param
|| 0.0)).toFixed(precision
)
1390 subst
= (+param
|| 0).toString(8);
1398 subst
= ('' + (+param
|| 0).toString(16)).toLowerCase();
1402 subst
= ('' + (+param
|| 0).toString(16)).toUpperCase();
1406 subst
= esc(param
, html_esc
);
1410 subst
= esc(param
, quot_esc
);
1417 var ts
= (param
|| 0);
1420 tm
= Math
.floor(ts
/ 60);
1425 th
= Math
.floor(tm
/ 60);
1430 td
= Math
.floor(th
/ 24);
1435 ? String
.format('%dd %dh %dm %ds', td
, th
, tm
, ts
)
1436 : String
.format('%dh %dm %ds', th
, tm
, ts
);
1441 var mf
= pMinLength
? +pMinLength
: 1000;
1442 var pr
= pPrecision
? ~~(10 * +('0' + pPrecision
)) : 2;
1445 var val
= (+param
|| 0);
1446 var units
= [ ' ', ' K', ' M', ' G', ' T', ' P', ' E' ];
1448 for (i
= 0; (i
< units
.length
) && (val
> mf
); i
++)
1451 subst
= (i
? val
.toFixed(pr
) : val
) + units
[i
];
1459 subst
= subst
.toString();
1460 for (var i
= subst
.length
; i
< pMinLength
; i
++)
1461 if (pJustify
== '-')
1462 subst
= subst
+ ' ';
1464 subst
= pad
+ subst
;
1467 out
+= leftpart
+ subst
;
1468 str
= str
.substr(m
.length
);
1474 String
.prototype.nobr = function()
1476 return this.replace(/[\s\n]+/g, ' ');
1479 String
.format = function()
1482 for (var i
= 1; i
< arguments
.length
; i
++)
1483 a
.push(arguments
[i
]);
1484 return ''.format
.apply(arguments
[0], a
);
1487 String
.nobr = function()
1490 for (var i
= 1; i
< arguments
.length
; i
++)
1491 a
.push(arguments
[i
]);
1492 return ''.nobr
.apply(arguments
[0], a
);
1496 var dummyElem
, domParser
;
1500 return (typeof(e
) === 'object' && e
!== null && 'nodeType' in e
);
1508 domParser
= domParser
|| new DOMParser();
1509 elem
= domParser
.parseFromString(s
, 'text/html').body
.firstChild
;
1515 dummyElem
= dummyElem
|| document
.createElement('div');
1516 dummyElem
.innerHTML
= s
;
1517 elem
= dummyElem
.firstChild
;
1522 return elem
|| null;
1527 var html
= arguments
[0],
1528 attr
= (arguments
[1] instanceof Object
&& !Array
.isArray(arguments
[1])) ? arguments
[1] : null,
1529 data
= attr
? arguments
[2] : arguments
[1],
1534 else if (html
.charCodeAt(0) === 60)
1535 elem
= toElem(html
);
1537 elem
= document
.createElement(html
);
1543 for (var key
in attr
)
1544 if (attr
.hasOwnProperty(key
))
1545 elem
.setAttribute(key
, attr
[key
]);
1547 if (typeof(data
) === 'function')
1551 elem
.appendChild(data
);
1553 else if (Array
.isArray(data
)) {
1554 for (var i
= 0; i
< data
.length
; i
++)
1555 if (isElem(data
[i
]))
1556 elem
.appendChild(data
[i
]);
1558 elem
.appendChild(document
.createTextNode('' + data
[i
]));
1560 else if (data
!== null && data
!== undefined) {
1561 elem
.innerHTML
= '' + data
;
1567 if (typeof(window
.CustomEvent
) !== 'function') {
1568 function CustomEvent(event
, params
) {
1569 params
= params
|| { bubbles
: false, cancelable
: false, detail
: undefined };
1570 var evt
= document
.createEvent('CustomEvent');
1571 evt
.initCustomEvent( event
, params
.bubbles
, params
.cancelable
, params
.detail
);
1575 CustomEvent
.prototype = window
.Event
.prototype;
1576 window
.CustomEvent
= CustomEvent
;
1580 openDropdown: function(sb
) {
1581 var st
= window
.getComputedStyle(sb
, null),
1582 ul
= sb
.querySelector('ul'),
1583 li
= ul
.querySelectorAll('li'),
1584 sel
= ul
.querySelector('[selected]'),
1585 rect
= sb
.getBoundingClientRect(),
1586 h
= sb
.clientHeight
- parseFloat(st
.paddingTop
) - parseFloat(st
.paddingBottom
),
1587 mh
= this.dropdown_items
* h
,
1588 eh
= Math
.min(mh
, li
.length
* h
);
1590 document
.querySelectorAll('.cbi-dropdown[open]').forEach(function(s
) {
1591 s
.dispatchEvent(new CustomEvent('cbi-dropdown-close', {}));
1594 ul
.style
.maxHeight
= mh
+ 'px';
1595 sb
.setAttribute('open', '');
1597 ul
.scrollTop
= sel
? Math
.max(sel
.offsetTop
- sel
.offsetHeight
, 0) : 0;
1598 ul
.querySelectorAll('[selected] input[type="checkbox"]').forEach(function(c
) {
1602 ul
.style
.top
= ul
.style
.bottom
= '';
1603 ul
.style
[((sb
.getBoundingClientRect().top
+ eh
) > window
.innerHeight
) ? 'bottom' : 'top'] = rect
.height
+ 'px';
1604 ul
.classList
.add('dropdown');
1606 var pv
= ul
.cloneNode(true);
1607 pv
.classList
.remove('dropdown');
1608 pv
.classList
.add('preview');
1610 sb
.insertBefore(pv
, ul
.nextElementSibling
);
1612 li
.forEach(function(l
) {
1613 l
.setAttribute('tabindex', 0);
1616 sb
.lastElementChild
.setAttribute('tabindex', 0);
1618 this.setFocus(sb
, sel
|| li
[0], true);
1621 closeDropdown: function(sb
, no_focus
) {
1622 if (!sb
.hasAttribute('open'))
1625 var pv
= sb
.querySelector('ul.preview'),
1626 ul
= sb
.querySelector('ul.dropdown'),
1627 li
= ul
.querySelectorAll('li');
1629 li
.forEach(function(l
) { l
.removeAttribute('tabindex'); });
1630 sb
.lastElementChild
.removeAttribute('tabindex');
1633 sb
.removeAttribute('open');
1634 sb
.style
.width
= sb
.style
.height
= '';
1636 ul
.classList
.remove('dropdown');
1639 this.setFocus(sb
, sb
);
1641 this.saveValues(sb
, ul
);
1644 toggleItem: function(sb
, li
, force_state
) {
1645 if (li
.hasAttribute('unselectable'))
1649 var cbox
= li
.querySelector('input[type="checkbox"]'),
1650 items
= li
.parentNode
.querySelectorAll('li'),
1651 label
= sb
.querySelector('ul.preview'),
1652 sel
= li
.parentNode
.querySelectorAll('[selected]').length
,
1653 more
= sb
.querySelector('.more'),
1654 ndisplay
= this.display_items
,
1657 if (li
.hasAttribute('selected')) {
1658 if (force_state
!== true) {
1659 if (sel
> 1 || this.optional
) {
1660 li
.removeAttribute('selected');
1661 cbox
.checked
= cbox
.disabled
= false;
1665 cbox
.disabled
= true;
1670 if (force_state
!== false) {
1671 li
.setAttribute('selected', '');
1672 cbox
.checked
= true;
1673 cbox
.disabled
= false;
1678 while (label
.firstElementChild
)
1679 label
.removeChild(label
.firstElementChild
);
1681 for (var i
= 0; i
< items
.length
; i
++) {
1682 items
[i
].removeAttribute('display');
1683 if (items
[i
].hasAttribute('selected')) {
1684 if (ndisplay
-- > 0) {
1685 items
[i
].setAttribute('display', n
++);
1686 label
.appendChild(items
[i
].cloneNode(true));
1688 var c
= items
[i
].querySelector('input[type="checkbox"]');
1690 c
.disabled
= (sel
== 1 && !this.optional
);
1695 sb
.setAttribute('more', '');
1697 sb
.removeAttribute('more');
1699 if (ndisplay
=== this.display_items
)
1700 sb
.setAttribute('empty', '');
1702 sb
.removeAttribute('empty');
1704 more
.innerHTML
= (ndisplay
=== this.display_items
) ? this.placeholder
: 'ยทยทยท';
1707 var sel
= li
.parentNode
.querySelector('[selected]');
1709 sel
.removeAttribute('display');
1710 sel
.removeAttribute('selected');
1713 li
.setAttribute('display', 0);
1714 li
.setAttribute('selected', '');
1716 this.closeDropdown(sb
, true);
1719 this.saveValues(sb
, li
.parentNode
);
1722 transformItem: function(sb
, li
) {
1723 var cbox
= E('form', {}, E('input', { type
: 'checkbox', tabindex
: -1, onclick
: 'event.preventDefault()' })),
1726 while (li
.firstChild
)
1727 label
.appendChild(li
.firstChild
);
1729 li
.appendChild(cbox
);
1730 li
.appendChild(label
);
1733 saveValues: function(sb
, ul
) {
1734 var sel
= ul
.querySelectorAll('[selected]'),
1735 div
= sb
.lastElementChild
;
1737 while (div
.lastElementChild
)
1738 div
.removeChild(div
.lastElementChild
);
1740 sel
.forEach(function (s
) {
1741 div
.appendChild(E('input', {
1743 name
: s
.hasAttribute('name') ? s
.getAttribute('name') : (sb
.getAttribute('name') || ''),
1744 value
: s
.hasAttribute('value') ? s
.getAttribute('value') : s
.innerText
1751 setFocus: function(sb
, elem
, scroll
) {
1752 if (sb
&& sb
.hasAttribute
&& sb
.hasAttribute('locked-in'))
1755 document
.querySelectorAll('.focus').forEach(function(e
) {
1756 if (e
.nodeName
.toLowerCase() !== 'input') {
1757 e
.classList
.remove('focus');
1764 elem
.classList
.add('focus');
1767 elem
.parentNode
.scrollTop
= elem
.offsetTop
- elem
.parentNode
.offsetTop
;
1771 createItems: function(sb
, value
) {
1773 val
= (value
|| '').trim().split(/\s+/),
1774 ul
= sb
.querySelector('ul');
1777 val
.length
= Math
.min(val
.length
, 1);
1779 val
.forEach(function(item
) {
1780 var new_item
= null;
1782 ul
.childNodes
.forEach(function(li
) {
1783 if (li
.getAttribute
&& li
.getAttribute('value') === item
)
1789 tpl
= sb
.querySelector(sbox
.template
);
1792 markup
= (tpl
.textContent
|| tpl
.innerHTML
|| tpl
.firstChild
.data
).replace(/^<!--|-->$/, '').trim();
1794 markup
= '<li value="{{value}}">{{value}}</li>';
1796 new_item
= E(markup
.replace(/{{value}}/g, item
));
1799 sbox
.transformItem(sb
, new_item
);
1802 var old
= ul
.querySelector('li[created]');
1804 ul
.removeChild(old
);
1806 new_item
.setAttribute('created', '');
1809 new_item
= ul
.insertBefore(new_item
, ul
.lastElementChild
);
1812 sbox
.toggleItem(sb
, new_item
, true);
1813 sbox
.setFocus(sb
, new_item
, true);
1817 closeAllDropdowns: function() {
1818 document
.querySelectorAll('.cbi-dropdown[open]').forEach(function(s
) {
1819 s
.dispatchEvent(new CustomEvent('cbi-dropdown-close', {}));
1823 findParent: function(node
, selector
) {
1825 if (node
.msMatchesSelector
&& node
.msMatchesSelector(selector
))
1827 else if (node
.matches
&& node
.matches(selector
))
1830 node
= node
.parentNode
;
1836 function cbi_dropdown_init(sb
) {
1837 if (!(this instanceof cbi_dropdown_init
))
1838 return new cbi_dropdown_init(sb
);
1840 this.multi
= sb
.hasAttribute('multiple');
1841 this.optional
= sb
.hasAttribute('optional');
1842 this.placeholder
= sb
.getAttribute('placeholder') || '---';
1843 this.display_items
= parseInt(sb
.getAttribute('display-items') || 3);
1844 this.dropdown_items
= parseInt(sb
.getAttribute('dropdown-items') || 5);
1845 this.create
= sb
.getAttribute('item-create') || '.create-item-input';
1846 this.template
= sb
.getAttribute('item-template') || 'script[type="item-template"]';
1849 ul
= sb
.querySelector('ul'),
1850 items
= ul
.querySelectorAll('li'),
1851 more
= sb
.appendChild(E('span', { class: 'more', tabindex
: -1 }, 'ยทยทยท')),
1852 open
= sb
.appendChild(E('span', { class: 'open', tabindex
: -1 }, 'โพ')),
1853 canary
= sb
.appendChild(E('div')),
1854 create
= sb
.querySelector(this.create
),
1855 ndisplay
= this.display_items
,
1859 for (var i
= 0; i
< items
.length
; i
++) {
1860 sbox
.transformItem(sb
, items
[i
]);
1862 if (items
[i
].hasAttribute('selected') && ndisplay
-- > 0)
1863 items
[i
].setAttribute('display', n
++);
1867 var sel
= sb
.querySelectorAll('[selected]');
1869 sel
.forEach(function(s
) {
1870 s
.removeAttribute('selected');
1873 var s
= sel
[0] || items
[0];
1875 s
.setAttribute('selected', '');
1876 s
.setAttribute('display', n
++);
1881 if (this.optional
&& !ul
.querySelector('li[value=""]')) {
1882 var placeholder
= E('li', { placeholder
: '' }, this.placeholder
);
1883 ul
.firstChild
? ul
.insertBefore(placeholder
, ul
.firstChild
) : ul
.appendChild(placeholder
);
1887 sbox
.saveValues(sb
, ul
);
1889 ul
.setAttribute('tabindex', -1);
1890 sb
.setAttribute('tabindex', 0);
1893 sb
.setAttribute('more', '')
1895 sb
.removeAttribute('more');
1897 if (ndisplay
=== this.display_items
)
1898 sb
.setAttribute('empty', '')
1900 sb
.removeAttribute('empty');
1902 more
.innerHTML
= (ndisplay
=== this.display_items
) ? this.placeholder
: 'ยทยทยท';
1905 sb
.addEventListener('click', function(ev
) {
1906 if (!this.hasAttribute('open')) {
1907 if (ev
.target
.nodeName
.toLowerCase() !== 'input')
1908 sbox
.openDropdown(this);
1911 var li
= sbox
.findParent(ev
.target
, 'li');
1912 if (li
&& li
.parentNode
.classList
.contains('dropdown'))
1913 sbox
.toggleItem(this, li
);
1916 ev
.preventDefault();
1917 ev
.stopPropagation();
1920 sb
.addEventListener('keydown', function(ev
) {
1921 if (ev
.target
.nodeName
.toLowerCase() === 'input')
1924 if (!this.hasAttribute('open')) {
1925 switch (ev
.keyCode
) {
1930 sbox
.openDropdown(this);
1931 ev
.preventDefault();
1936 var active
= sbox
.findParent(document
.activeElement
, 'li');
1938 switch (ev
.keyCode
) {
1940 sbox
.closeDropdown(this);
1945 if (!active
.hasAttribute('selected'))
1946 sbox
.toggleItem(this, active
);
1947 sbox
.closeDropdown(this);
1948 ev
.preventDefault();
1954 sbox
.toggleItem(this, active
);
1955 ev
.preventDefault();
1960 if (active
&& active
.previousElementSibling
) {
1961 sbox
.setFocus(this, active
.previousElementSibling
);
1962 ev
.preventDefault();
1967 if (active
&& active
.nextElementSibling
) {
1968 sbox
.setFocus(this, active
.nextElementSibling
);
1969 ev
.preventDefault();
1976 sb
.addEventListener('cbi-dropdown-close', function(ev
) {
1977 sbox
.closeDropdown(this, true);
1980 if ('ontouchstart' in window
) {
1981 sb
.addEventListener('touchstart', function(ev
) { ev
.stopPropagation(); });
1982 window
.addEventListener('touchstart', sbox
.closeAllDropdowns
);
1985 sb
.addEventListener('mouseover', function(ev
) {
1986 if (!this.hasAttribute('open'))
1989 var li
= sbox
.findParent(ev
.target
, 'li');
1991 if (li
.parentNode
.classList
.contains('dropdown'))
1992 sbox
.setFocus(this, li
);
1994 ev
.stopPropagation();
1998 sb
.addEventListener('focus', function(ev
) {
1999 document
.querySelectorAll('.cbi-dropdown[open]').forEach(function(s
) {
2000 if (s
!== this || this.hasAttribute('open'))
2001 s
.dispatchEvent(new CustomEvent('cbi-dropdown-close', {}));
2005 canary
.addEventListener('focus', function(ev
) {
2006 sbox
.closeDropdown(this.parentNode
);
2009 window
.addEventListener('mouseover', sbox
.setFocus
);
2010 window
.addEventListener('click', sbox
.closeAllDropdowns
);
2014 create
.addEventListener('keydown', function(ev
) {
2015 switch (ev
.keyCode
) {
2017 sbox
.createItems(sb
, this.value
);
2018 ev
.preventDefault();
2025 create
.addEventListener('focus', function(ev
) {
2026 var cbox
= sbox
.findParent(this, 'li').querySelector('input[type="checkbox"]');
2027 if (cbox
) cbox
.checked
= true;
2028 sb
.setAttribute('locked-in', '');
2031 create
.addEventListener('blur', function(ev
) {
2032 var cbox
= sbox
.findParent(this, 'li').querySelector('input[type="checkbox"]');
2033 if (cbox
) cbox
.checked
= false;
2034 sb
.removeAttribute('locked-in');
2037 var li
= sbox
.findParent(create
, 'li');
2039 li
.setAttribute('unselectable', '');
2040 li
.addEventListener('click', function(ev
) {
2041 this.querySelector(sbox
.create
).focus();
2046 cbi_dropdown_init
.prototype = CBIDropdown
;