X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fluci-base%2Fhtdocs%2Fluci-static%2Fresources%2Fcbi.js;h=55e0c4d0af6c8cfbbdaba1c1b83b2a6b35a4a8fc;hp=1c4123bdadcb3cd7465e1277678ddede2b67137f;hb=2bd428ad8a76cad41c1d7cf5d6196ca62ab07695;hpb=e19098d0623e96690e65539b36c59965ae1373d5 diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 1c4123bda..55e0c4d0a 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -13,7 +13,6 @@ var cbi_d = []; var cbi_t = []; -var cbi_c = []; var cbi_validators = { @@ -345,7 +344,7 @@ var cbi_validators = { { return (this.match(/^[0-9\*#!\.]+$/) != null); }, - 'timehhmmss': function() + 'timehhmmss': function() { return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null); }, @@ -389,12 +388,12 @@ var cbi_validators = { }; -function cbi_d_add(field, dep, next) { - var obj = document.getElementById(field); +function cbi_d_add(field, dep, index) { + var obj = (typeof(field) === 'string') ? document.getElementById(field) : field; if (obj) { var entry for (var i=0; i entry.index) { + break; + } + } + if (!next) { parent.appendChild(entry.node); } else { - next.parentNode.insertBefore(entry.node, next); + parent.insertBefore(entry.node, next); } + state = true; - if( entry.parent ) - cbi_c[entry.parent]++; } } @@ -499,6 +502,31 @@ function cbi_d_update() { } } +function cbi_init() { + var 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-change]'); + + for (var i = 0, node; (node = nodes[i]) !== undefined; i++) { + var events = node.getAttribute('data-change').split(' '); + for (var j = 0, event; (event = events[j]) !== undefined; j++) { + cbi_bind(node, event, cbi_d_update); + } + } + + cbi_d_update(); +} + function cbi_bind(obj, type, callback, mode) { if (!obj.addEventListener) { obj.attachEvent('on' + type, @@ -517,7 +545,7 @@ function cbi_bind(obj, type, callback, mode) { return obj; } -function cbi_combobox(id, values, def, man) { +function cbi_combobox(id, values, def, man, focus) { var selid = "cbi.combobox." + id; if (document.getElementById(selid)) { return @@ -577,6 +605,7 @@ function cbi_combobox(id, values, def, man) { cbi_bind(sel, "change", function() { if (sel.selectedIndex == sel.options.length - 1) { obj.style.display = "inline"; + sel.blur(); sel.parentNode.removeChild(sel); obj.focus(); } else { @@ -591,16 +620,18 @@ function cbi_combobox(id, values, def, man) { }) // Retrigger validation in select - sel.focus(); - sel.blur(); + if (focus) { + sel.focus(); + sel.blur(); + } } function cbi_combobox_init(id, values, def, man) { var obj = document.getElementById(id); cbi_bind(obj, "blur", function() { - cbi_combobox(id, values, def, man) + cbi_combobox(id, values, def, man, true); }); - cbi_combobox(id, values, def, man); + cbi_combobox(id, values, def, man, false); } function cbi_filebrowser(id, url, defpath) { @@ -876,27 +907,6 @@ function cbi_dynlist_init(name, respath, datatype, optional, url, defpath, choic cbi_dynlist_redraw(NaN, -1, -1); } -//Hijacks the CBI form to send via XHR (requires Prototype) -function cbi_hijack_forms(layer, win, fail, load) { - var forms = layer.getElementsByTagName('form'); - for (var i=0; i 0 ) + if (hl_tabs.length > 0) window.setTimeout(function() { for( var i = 0; i < hl_tabs.length; i++ ) hl_tabs[i].className = hl_tabs[i].className.replace(/ cbi-tab-highlighted/g, '');