luci-base: cbi.js: support plural translations and disambiguation contexts
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / cbi.js
1 /*
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008-2018 Jo-Philipp Wich <jo@mein.io>
6
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
10
11 http://www.apache.org/licenses/LICENSE-2.0
12 */
13
14 var cbi_d = [];
15 var cbi_strings = { path: {}, label: {} };
16
17 function s8(bytes, off) {
18 var n = bytes[off];
19 return (n > 0x7F) ? (n - 256) >>> 0 : n;
20 }
21
22 function u16(bytes, off) {
23 return ((bytes[off + 1] << 8) + bytes[off]) >>> 0;
24 }
25
26 function sfh(s) {
27 if (s === null || s.length === 0)
28 return null;
29
30 var bytes = [];
31
32 for (var i = 0; i < s.length; i++) {
33 var ch = s.charCodeAt(i);
34
35 if (ch <= 0x7F)
36 bytes.push(ch);
37 else if (ch <= 0x7FF)
38 bytes.push(((ch >>> 6) & 0x1F) | 0xC0,
39 ( ch & 0x3F) | 0x80);
40 else if (ch <= 0xFFFF)
41 bytes.push(((ch >>> 12) & 0x0F) | 0xE0,
42 ((ch >>> 6) & 0x3F) | 0x80,
43 ( ch & 0x3F) | 0x80);
44 else if (code <= 0x10FFFF)
45 bytes.push(((ch >>> 18) & 0x07) | 0xF0,
46 ((ch >>> 12) & 0x3F) | 0x80,
47 ((ch >> 6) & 0x3F) | 0x80,
48 ( ch & 0x3F) | 0x80);
49 }
50
51 if (!bytes.length)
52 return null;
53
54 var hash = (bytes.length >>> 0),
55 len = (bytes.length >>> 2),
56 off = 0, tmp;
57
58 while (len--) {
59 hash += u16(bytes, off);
60 tmp = ((u16(bytes, off + 2) << 11) ^ hash) >>> 0;
61 hash = ((hash << 16) ^ tmp) >>> 0;
62 hash += hash >>> 11;
63 off += 4;
64 }
65
66 switch ((bytes.length & 3) >>> 0) {
67 case 3:
68 hash += u16(bytes, off);
69 hash = (hash ^ (hash << 16)) >>> 0;
70 hash = (hash ^ (s8(bytes, off + 2) << 18)) >>> 0;
71 hash += hash >>> 11;
72 break;
73
74 case 2:
75 hash += u16(bytes, off);
76 hash = (hash ^ (hash << 11)) >>> 0;
77 hash += hash >>> 17;
78 break;
79
80 case 1:
81 hash += s8(bytes, off);
82 hash = (hash ^ (hash << 10)) >>> 0;
83 hash += hash >>> 1;
84 break;
85 }
86
87 hash = (hash ^ (hash << 3)) >>> 0;
88 hash += hash >>> 5;
89 hash = (hash ^ (hash << 4)) >>> 0;
90 hash += hash >>> 17;
91 hash = (hash ^ (hash << 25)) >>> 0;
92 hash += hash >>> 6;
93
94 return (0x100000000 + hash).toString(16).substr(1);
95 }
96
97 var plural_function = null;
98
99 function trimws(s) {
100 return String(s).trim().replace(/[ \t\n]+/g, ' ');
101 }
102
103 function _(s, c) {
104 return (window.TR && TR[sfh(trimws(s))]) || s;
105 }
106
107 function N_(n, s, p, c) {
108 if (plural_function == null && window.TR)
109 plural_function = new Function('n', (TR['00000000'] || 'plural=(n != 1);') + 'return +plural');
110
111 var i = plural_function ? plural_function(n) : (n != 1),
112 k = (c != null ? trimws(c) + '\u0001' : '') + trimws(s) + '\u0002' + i.toString();
113
114 return (window.TR && TR[sfh(k)]) || (i ? p : s);
115 }
116
117
118 function cbi_d_add(field, dep, index) {
119 var obj = (typeof(field) === 'string') ? document.getElementById(field) : field;
120 if (obj) {
121 var entry
122 for (var i=0; i<cbi_d.length; i++) {
123 if (cbi_d[i].id == obj.id) {
124 entry = cbi_d[i];
125 break;
126 }
127 }
128 if (!entry) {
129 entry = {
130 "node": obj,
131 "id": obj.id,
132 "parent": obj.parentNode.id,
133 "deps": [],
134 "index": index
135 };
136 cbi_d.unshift(entry);
137 }
138 entry.deps.push(dep)
139 }
140 }
141
142 function cbi_d_checkvalue(target, ref) {
143 var value = null,
144 query = 'input[id="'+target+'"], input[name="'+target+'"], ' +
145 'select[id="'+target+'"], select[name="'+target+'"]';
146
147 document.querySelectorAll(query).forEach(function(i) {
148 if (value === null && ((i.type !== 'radio' && i.type !== 'checkbox') || i.checked === true))
149 value = i.value;
150 });
151
152 return (((value !== null) ? value : "") == ref);
153 }
154
155 function cbi_d_check(deps) {
156 var reverse;
157 var def = false;
158 for (var i=0; i<deps.length; i++) {
159 var istat = true;
160 reverse = false;
161 for (var j in deps[i]) {
162 if (j == "!reverse") {
163 reverse = true;
164 } else if (j == "!default") {
165 def = true;
166 istat = false;
167 } else {
168 istat = (istat && cbi_d_checkvalue(j, deps[i][j]))
169 }
170 }
171
172 if (istat ^ reverse) {
173 return true;
174 }
175 }
176 return def;
177 }
178
179 function cbi_d_update() {
180 var state = false;
181 for (var i=0; i<cbi_d.length; i++) {
182 var entry = cbi_d[i];
183 var node = document.getElementById(entry.id);
184 var parent = document.getElementById(entry.parent);
185
186 if (node && node.parentNode && !cbi_d_check(entry.deps)) {
187 node.parentNode.removeChild(node);
188 state = true;
189 }
190 else if (parent && (!node || !node.parentNode) && cbi_d_check(entry.deps)) {
191 var next = undefined;
192
193 for (next = parent.firstChild; next; next = next.nextSibling) {
194 if (next.getAttribute && parseInt(next.getAttribute('data-index'), 10) > entry.index)
195 break;
196 }
197
198 if (!next)
199 parent.appendChild(entry.node);
200 else
201 parent.insertBefore(entry.node, next);
202
203 state = true;
204 }
205
206 // hide optionals widget if no choices remaining
207 if (parent && parent.parentNode && parent.getAttribute('data-optionals'))
208 parent.parentNode.style.display = (parent.options.length <= 1) ? 'none' : '';
209 }
210
211 if (entry && entry.parent)
212 cbi_tag_last(parent);
213
214 if (state)
215 cbi_d_update();
216 else if (parent)
217 parent.dispatchEvent(new CustomEvent('dependency-update', { bubbles: true }));
218 }
219
220 function cbi_init() {
221 var nodes;
222
223 document.querySelectorAll('.cbi-dropdown').forEach(function(node) {
224 cbi_dropdown_init(node);
225 node.addEventListener('cbi-dropdown-change', cbi_d_update);
226 });
227
228 nodes = document.querySelectorAll('[data-strings]');
229
230 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
231 var str = JSON.parse(node.getAttribute('data-strings'));
232 for (var key in str) {
233 for (var key2 in str[key]) {
234 var dst = cbi_strings[key] || (cbi_strings[key] = { });
235 dst[key2] = str[key][key2];
236 }
237 }
238 }
239
240 nodes = document.querySelectorAll('[data-depends]');
241
242 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
243 var index = parseInt(node.getAttribute('data-index'), 10);
244 var depends = JSON.parse(node.getAttribute('data-depends'));
245 if (!isNaN(index) && depends.length > 0) {
246 for (var alt = 0; alt < depends.length; alt++)
247 cbi_d_add(node, depends[alt], index);
248 }
249 }
250
251 nodes = document.querySelectorAll('[data-update]');
252
253 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
254 var events = node.getAttribute('data-update').split(' ');
255 for (var j = 0, event; (event = events[j]) !== undefined; j++)
256 node.addEventListener(event, cbi_d_update);
257 }
258
259 nodes = document.querySelectorAll('[data-choices]');
260
261 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
262 var choices = JSON.parse(node.getAttribute('data-choices')),
263 options = {};
264
265 for (var j = 0; j < choices[0].length; j++)
266 options[choices[0][j]] = choices[1][j];
267
268 var def = (node.getAttribute('data-optional') === 'true')
269 ? node.placeholder || '' : null;
270
271 var cb = new L.ui.Combobox(node.value, options, {
272 name: node.getAttribute('name'),
273 sort: choices[0],
274 select_placeholder: def || _('-- Please choose --'),
275 custom_placeholder: node.getAttribute('data-manual') || _('-- custom --')
276 });
277
278 var n = cb.render();
279 n.addEventListener('cbi-dropdown-change', cbi_d_update);
280 node.parentNode.replaceChild(n, node);
281 }
282
283 nodes = document.querySelectorAll('[data-dynlist]');
284
285 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
286 var choices = JSON.parse(node.getAttribute('data-dynlist')),
287 values = JSON.parse(node.getAttribute('data-values') || '[]'),
288 options = null;
289
290 if (choices[0] && choices[0].length) {
291 options = {};
292
293 for (var j = 0; j < choices[0].length; j++)
294 options[choices[0][j]] = choices[1][j];
295 }
296
297 var dl = new L.ui.DynamicList(values, options, {
298 name: node.getAttribute('data-prefix'),
299 sort: choices[0],
300 datatype: choices[2],
301 optional: choices[3],
302 placeholder: node.getAttribute('data-placeholder')
303 });
304
305 var n = dl.render();
306 n.addEventListener('cbi-dynlist-change', cbi_d_update);
307 node.parentNode.replaceChild(n, node);
308 }
309
310 nodes = document.querySelectorAll('[data-type]');
311
312 for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
313 cbi_validate_field(node, node.getAttribute('data-optional') === 'true',
314 node.getAttribute('data-type'));
315 }
316
317 document.querySelectorAll('.cbi-tooltip:not(:empty)').forEach(function(s) {
318 s.parentNode.classList.add('cbi-tooltip-container');
319 });
320
321 document.querySelectorAll('.cbi-section-remove > input[name^="cbi.rts"]').forEach(function(i) {
322 var handler = function(ev) {
323 var bits = this.name.split(/\./),
324 section = document.getElementById('cbi-' + bits[2] + '-' + bits[3]);
325
326 section.style.opacity = (ev.type === 'mouseover') ? 0.5 : '';
327 };
328
329 i.addEventListener('mouseover', handler);
330 i.addEventListener('mouseout', handler);
331 });
332
333 var tasks = [];
334
335 document.querySelectorAll('[data-ui-widget]').forEach(function(node) {
336 var args = JSON.parse(node.getAttribute('data-ui-widget') || '[]'),
337 widget = new (Function.prototype.bind.apply(L.ui[args[0]], args)),
338 markup = widget.render();
339
340 tasks.push(Promise.resolve(markup).then(function(markup) {
341 markup.addEventListener('widget-change', cbi_d_update);
342 node.parentNode.replaceChild(markup, node);
343 }));
344 });
345
346 Promise.all(tasks).then(cbi_d_update);
347 }
348
349 function cbi_validate_form(form, errmsg)
350 {
351 /* if triggered by a section removal or addition, don't validate */
352 if (form.cbi_state == 'add-section' || form.cbi_state == 'del-section')
353 return true;
354
355 if (form.cbi_validators) {
356 for (var i = 0; i < form.cbi_validators.length; i++) {
357 var validator = form.cbi_validators[i];
358
359 if (!validator() && errmsg) {
360 alert(errmsg);
361 return false;
362 }
363 }
364 }
365
366 return true;
367 }
368
369 function cbi_validate_reset(form)
370 {
371 window.setTimeout(
372 function() { cbi_validate_form(form, null) }, 100
373 );
374
375 return true;
376 }
377
378 function cbi_validate_field(cbid, optional, type)
379 {
380 var field = isElem(cbid) ? cbid : document.getElementById(cbid);
381 var validatorFn;
382
383 try {
384 var cbiValidator = L.validation.create(field, type, optional);
385 validatorFn = cbiValidator.validate.bind(cbiValidator);
386 }
387 catch(e) {
388 validatorFn = null;
389 };
390
391 if (validatorFn !== null) {
392 var form = findParent(field, 'form');
393
394 if (!form.cbi_validators)
395 form.cbi_validators = [ ];
396
397 form.cbi_validators.push(validatorFn);
398
399 field.addEventListener("blur", validatorFn);
400 field.addEventListener("keyup", validatorFn);
401 field.addEventListener("cbi-dropdown-change", validatorFn);
402
403 if (matchesElem(field, 'select')) {
404 field.addEventListener("change", validatorFn);
405 field.addEventListener("click", validatorFn);
406 }
407
408 validatorFn();
409 }
410 }
411
412 function cbi_row_swap(elem, up, store)
413 {
414 var tr = findParent(elem.parentNode, '.cbi-section-table-row');
415
416 if (!tr)
417 return false;
418
419 tr.classList.remove('flash');
420
421 if (up) {
422 var prev = tr.previousElementSibling;
423
424 if (prev && prev.classList.contains('cbi-section-table-row'))
425 tr.parentNode.insertBefore(tr, prev);
426 else
427 return;
428 }
429 else {
430 var next = tr.nextElementSibling ? tr.nextElementSibling.nextElementSibling : null;
431
432 if (next && next.classList.contains('cbi-section-table-row'))
433 tr.parentNode.insertBefore(tr, next);
434 else if (!next)
435 tr.parentNode.appendChild(tr);
436 else
437 return;
438 }
439
440 var ids = [ ];
441
442 for (var i = 0, n = 0; i < tr.parentNode.childNodes.length; i++) {
443 var node = tr.parentNode.childNodes[i];
444 if (node.classList && node.classList.contains('cbi-section-table-row')) {
445 node.classList.remove('cbi-rowstyle-1');
446 node.classList.remove('cbi-rowstyle-2');
447 node.classList.add((n++ % 2) ? 'cbi-rowstyle-2' : 'cbi-rowstyle-1');
448
449 if (/-([^\-]+)$/.test(node.id))
450 ids.push(RegExp.$1);
451 }
452 }
453
454 var input = document.getElementById(store);
455 if (input)
456 input.value = ids.join(' ');
457
458 window.scrollTo(0, tr.offsetTop);
459 void tr.offsetWidth;
460 tr.classList.add('flash');
461
462 return false;
463 }
464
465 function cbi_tag_last(container)
466 {
467 var last;
468
469 for (var i = 0; i < container.childNodes.length; i++) {
470 var c = container.childNodes[i];
471 if (matchesElem(c, 'div')) {
472 c.classList.remove('cbi-value-last');
473 last = c;
474 }
475 }
476
477 if (last)
478 last.classList.add('cbi-value-last');
479 }
480
481 function cbi_submit(elem, name, value, action)
482 {
483 var form = elem.form || findParent(elem, 'form');
484
485 if (!form)
486 return false;
487
488 if (action)
489 form.action = action;
490
491 if (name) {
492 var hidden = form.querySelector('input[type="hidden"][name="%s"]'.format(name)) ||
493 E('input', { type: 'hidden', name: name });
494
495 hidden.value = value || '1';
496 form.appendChild(hidden);
497 }
498
499 form.submit();
500 return true;
501 }
502
503 String.prototype.format = function()
504 {
505 if (!RegExp)
506 return;
507
508 var html_esc = [/&/g, '&#38;', /"/g, '&#34;', /'/g, '&#39;', /</g, '&#60;', />/g, '&#62;'];
509 var quot_esc = [/"/g, '&#34;', /'/g, '&#39;'];
510
511 function esc(s, r) {
512 if (typeof(s) !== 'string' && !(s instanceof String))
513 return '';
514
515 for (var i = 0; i < r.length; i += 2)
516 s = s.replace(r[i], r[i+1]);
517
518 return s;
519 }
520
521 var str = this;
522 var out = '';
523 var re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/;
524 var a = b = [], numSubstitutions = 0, numMatches = 0;
525
526 while (a = re.exec(str)) {
527 var m = a[1];
528 var leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5];
529 var pPrecision = a[6], pType = a[7];
530
531 numMatches++;
532
533 if (pType == '%') {
534 subst = '%';
535 }
536 else {
537 if (numSubstitutions < arguments.length) {
538 var param = arguments[numSubstitutions++];
539
540 var pad = '';
541 if (pPad && pPad.substr(0,1) == "'")
542 pad = leftpart.substr(1,1);
543 else if (pPad)
544 pad = pPad;
545 else
546 pad = ' ';
547
548 var justifyRight = true;
549 if (pJustify && pJustify === "-")
550 justifyRight = false;
551
552 var minLength = -1;
553 if (pMinLength)
554 minLength = +pMinLength;
555
556 var precision = -1;
557 if (pPrecision && pType == 'f')
558 precision = +pPrecision.substring(1);
559
560 var subst = param;
561
562 switch(pType) {
563 case 'b':
564 subst = Math.floor(+param || 0).toString(2);
565 break;
566
567 case 'c':
568 subst = String.fromCharCode(+param || 0);
569 break;
570
571 case 'd':
572 subst = Math.floor(+param || 0).toFixed(0);
573 break;
574
575 case 'u':
576 var n = +param || 0;
577 subst = Math.floor((n < 0) ? 0x100000000 + n : n).toFixed(0);
578 break;
579
580 case 'f':
581 subst = (precision > -1)
582 ? ((+param || 0.0)).toFixed(precision)
583 : (+param || 0.0);
584 break;
585
586 case 'o':
587 subst = Math.floor(+param || 0).toString(8);
588 break;
589
590 case 's':
591 subst = param;
592 break;
593
594 case 'x':
595 subst = Math.floor(+param || 0).toString(16).toLowerCase();
596 break;
597
598 case 'X':
599 subst = Math.floor(+param || 0).toString(16).toUpperCase();
600 break;
601
602 case 'h':
603 subst = esc(param, html_esc);
604 break;
605
606 case 'q':
607 subst = esc(param, quot_esc);
608 break;
609
610 case 't':
611 var td = 0;
612 var th = 0;
613 var tm = 0;
614 var ts = (param || 0);
615
616 if (ts > 60) {
617 tm = Math.floor(ts / 60);
618 ts = (ts % 60);
619 }
620
621 if (tm > 60) {
622 th = Math.floor(tm / 60);
623 tm = (tm % 60);
624 }
625
626 if (th > 24) {
627 td = Math.floor(th / 24);
628 th = (th % 24);
629 }
630
631 subst = (td > 0)
632 ? String.format('%dd %dh %dm %ds', td, th, tm, ts)
633 : String.format('%dh %dm %ds', th, tm, ts);
634
635 break;
636
637 case 'm':
638 var mf = pMinLength ? +pMinLength : 1000;
639 var pr = pPrecision ? ~~(10 * +('0' + pPrecision)) : 2;
640
641 var i = 0;
642 var val = (+param || 0);
643 var units = [ ' ', ' K', ' M', ' G', ' T', ' P', ' E' ];
644
645 for (i = 0; (i < units.length) && (val > mf); i++)
646 val /= mf;
647
648 subst = (i ? val.toFixed(pr) : val) + units[i];
649 pMinLength = null;
650 break;
651 }
652 }
653 }
654
655 if (pMinLength) {
656 subst = subst.toString();
657 for (var i = subst.length; i < pMinLength; i++)
658 if (pJustify == '-')
659 subst = subst + ' ';
660 else
661 subst = pad + subst;
662 }
663
664 out += leftpart + subst;
665 str = str.substr(m.length);
666 }
667
668 return out + str;
669 }
670
671 String.prototype.nobr = function()
672 {
673 return this.replace(/[\s\n]+/g, '&#160;');
674 }
675
676 String.format = function()
677 {
678 var a = [ ];
679
680 for (var i = 1; i < arguments.length; i++)
681 a.push(arguments[i]);
682
683 return ''.format.apply(arguments[0], a);
684 }
685
686 String.nobr = function()
687 {
688 var a = [ ];
689
690 for (var i = 1; i < arguments.length; i++)
691 a.push(arguments[i]);
692
693 return ''.nobr.apply(arguments[0], a);
694 }
695
696 if (window.NodeList && !NodeList.prototype.forEach) {
697 NodeList.prototype.forEach = function (callback, thisArg) {
698 thisArg = thisArg || window;
699 for (var i = 0; i < this.length; i++) {
700 callback.call(thisArg, this[i], i, this);
701 }
702 };
703 }
704
705 if (!window.requestAnimationFrame) {
706 window.requestAnimationFrame = function(f) {
707 window.setTimeout(function() {
708 f(new Date().getTime())
709 }, 1000/30);
710 };
711 }
712
713
714 function isElem(e) { return L.dom.elem(e) }
715 function toElem(s) { return L.dom.parse(s) }
716 function matchesElem(node, selector) { return L.dom.matches(node, selector) }
717 function findParent(node, selector) { return L.dom.parent(node, selector) }
718 function E() { return L.dom.create.apply(L.dom, arguments) }
719
720 if (typeof(window.CustomEvent) !== 'function') {
721 function CustomEvent(event, params) {
722 params = params || { bubbles: false, cancelable: false, detail: undefined };
723 var evt = document.createEvent('CustomEvent');
724 evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
725 return evt;
726 }
727
728 CustomEvent.prototype = window.Event.prototype;
729 window.CustomEvent = CustomEvent;
730 }
731
732 function cbi_dropdown_init(sb) {
733 var dl = new L.ui.Dropdown(sb, null, { name: sb.getAttribute('name') });
734 return dl.bind(sb);
735 }
736
737 function cbi_update_table(table, data, placeholder) {
738 var target = isElem(table) ? table : document.querySelector(table);
739
740 if (!isElem(target))
741 return;
742
743 target.querySelectorAll('.tr.table-titles, .cbi-section-table-titles').forEach(function(thead) {
744 var titles = [];
745
746 thead.querySelectorAll('.th').forEach(function(th) {
747 titles.push(th);
748 });
749
750 if (Array.isArray(data)) {
751 var n = 0, rows = target.querySelectorAll('.tr');
752
753 data.forEach(function(row) {
754 var trow = E('div', { 'class': 'tr' });
755
756 for (var i = 0; i < titles.length; i++) {
757 var text = (titles[i].innerText || '').trim();
758 var td = trow.appendChild(E('div', {
759 'class': titles[i].className,
760 'data-title': (text !== '') ? text : null
761 }, row[i] || ''));
762
763 td.classList.remove('th');
764 td.classList.add('td');
765 }
766
767 trow.classList.add('cbi-rowstyle-%d'.format((n++ % 2) ? 2 : 1));
768
769 if (rows[n])
770 target.replaceChild(trow, rows[n]);
771 else
772 target.appendChild(trow);
773 });
774
775 while (rows[++n])
776 target.removeChild(rows[n]);
777
778 if (placeholder && target.firstElementChild === target.lastElementChild) {
779 var trow = target.appendChild(E('div', { 'class': 'tr placeholder' }));
780 var td = trow.appendChild(E('div', { 'class': titles[0].className }, placeholder));
781
782 td.classList.remove('th');
783 td.classList.add('td');
784 }
785 }
786 else {
787 thead.parentNode.style.display = 'none';
788
789 thead.parentNode.querySelectorAll('.tr, .cbi-section-table-row').forEach(function(trow) {
790 if (trow !== thead) {
791 var n = 0;
792 trow.querySelectorAll('.th, .td').forEach(function(td) {
793 if (n < titles.length) {
794 var text = (titles[n++].innerText || '').trim();
795 if (text !== '')
796 td.setAttribute('data-title', text);
797 }
798 });
799 }
800 });
801
802 thead.parentNode.style.display = '';
803 }
804 });
805 }
806
807 function showModal(title, children)
808 {
809 return L.showModal(title, children);
810 }
811
812 function hideModal()
813 {
814 return L.hideModal();
815 }
816
817
818 document.addEventListener('DOMContentLoaded', function() {
819 document.addEventListener('validation-failure', function(ev) {
820 if (ev.target === document.activeElement)
821 L.showTooltip(ev);
822 });
823
824 document.addEventListener('validation-success', function(ev) {
825 if (ev.target === document.activeElement)
826 L.hideTooltip(ev);
827 });
828
829 document.querySelectorAll('.table').forEach(cbi_update_table);
830 });