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