+function cbi_init() {
+ var nodes;
+
+ nodes = document.querySelectorAll('[data-strings]');
+
+ for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+ var str = JSON.parse(node.getAttribute('data-strings'));
+ for (var key in str) {
+ for (var key2 in str[key]) {
+ var dst = cbi_strings[key] || (cbi_strings[key] = { });
+ dst[key2] = str[key][key2];
+ }
+ }
+ }
+
+ nodes = document.querySelectorAll('[data-depends]');
+
+ for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+ var index = parseInt(node.getAttribute('data-index'), 10);
+ var depends = JSON.parse(node.getAttribute('data-depends'));
+ if (!isNaN(index) && depends.length > 0) {
+ for (var alt = 0; alt < depends.length; alt++) {
+ cbi_d_add(node, depends[alt], index);
+ }
+ }
+ }
+
+ nodes = document.querySelectorAll('[data-update]');
+
+ for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+ var events = node.getAttribute('data-update').split(' ');
+ for (var j = 0, event; (event = events[j]) !== undefined; j++) {
+ cbi_bind(node, event, cbi_d_update);
+ }
+ }
+
+ nodes = document.querySelectorAll('[data-choices]');
+
+ for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+ var choices = JSON.parse(node.getAttribute('data-choices'));
+ var options = {};
+
+ for (var j = 0; j < choices[0].length; j++)
+ options[choices[0][j]] = choices[1][j];
+
+ var def = (node.getAttribute('data-optional') === 'true')
+ ? node.placeholder || '' : null;
+
+ cbi_combobox_init(node, options, def,
+ node.getAttribute('data-manual'));
+ }
+
+ nodes = document.querySelectorAll('[data-dynlist]');
+
+ for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+ var choices = JSON.parse(node.getAttribute('data-dynlist'));
+ var options = null;
+
+ if (choices[0] && choices[0].length) {
+ options = {};
+
+ for (var j = 0; j < choices[0].length; j++)
+ options[choices[0][j]] = choices[1][j];
+ }
+
+ cbi_dynlist_init(node, choices[2], choices[3], options);
+ }
+
+ nodes = document.querySelectorAll('[data-type]');
+
+ for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+ cbi_validate_field(node, node.getAttribute('data-optional') === 'true',
+ node.getAttribute('data-type'));
+ }
+
+ cbi_d_update();
+}
+