diff options
author | Steven Barth <steven@midlink.org> | 2008-08-04 17:16:27 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-08-04 17:16:27 +0000 |
commit | 084db952ce2aa302a42f35fa34866f34cb06ba99 (patch) | |
tree | 41bcdef71918816ff78de209455edf1162fc8a9f /libs/cbi/htdocs/luci-static | |
parent | 513e1cbba9e8ba98cc0b4f667aa89233b72b4dd1 (diff) |
libs/cbi: Added value function to luci.cbi.Value to create Comboboxes
Diffstat (limited to 'libs/cbi/htdocs/luci-static')
-rw-r--r-- | libs/cbi/htdocs/luci-static/resources/cbi.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libs/cbi/htdocs/luci-static/resources/cbi.js b/libs/cbi/htdocs/luci-static/resources/cbi.js index 3abc3a9f5..38e27d8f4 100644 --- a/libs/cbi/htdocs/luci-static/resources/cbi.js +++ b/libs/cbi/htdocs/luci-static/resources/cbi.js @@ -35,4 +35,77 @@ function cbi_d_init() { for (var x in cbi_d) { cbi_d_update(x); } +} + +function cbi_bind(obj, type, callback, mode) { + if (typeof mode == "undefined") { + mode = false; + } + if (!obj.addEventListener) { + ieCallback = function(){ + var e = window.event; + if (!e.target && e.srcElement) { + e.target = e.srcElement; + }; + e.target['_eCB' + type + callback] = callback; + e.target['_eCB' + type + callback](e); + e.target['_eCB' + type + callback] = null; + }; + obj.attachEvent('on' + type, ieCallback); + } else { + obj.addEventListener(type, callback, mode); + } + return obj; +} + +function cbi_combobox(id, values, def, man) { + var obj = document.getElementById(id) + if (obj.value == "" || values[obj.value]) { + var sel = document.createElement("select") + obj.parentNode.appendChild(sel) + + if (obj.value == "") { + var optdef = document.createElement("option") + optdef.value = "" + optdef.appendChild(document.createTextNode(def)) + sel.appendChild(optdef) + } + + for (var i in values) { + var opt = document.createElement("option") + opt.value = i + + if (obj.value == i) { + opt.selected = "selected" + } + + opt.appendChild(document.createTextNode(values[i])) + sel.appendChild(opt) + } + + var optman = document.createElement("option") + optman.value = "" + optman.appendChild(document.createTextNode(man)) + sel.appendChild(optman) + + obj.style.display = "none" + + cbi_bind(sel, "change", function() { + obj.value = sel.options[sel.selectedIndex].value + + if (sel.selectedIndex == sel.options.length - 1) { + obj.style.display = "inline" + sel.parentNode.removeChild(sel) + obj.focus() + } + }) + } +} + +function cbi_combobox_init(id, values, def, man) { + var obj = document.getElementById(id) + cbi_bind(obj, "change", function() { + cbi_combobox(id, values, def, man) + }) + cbi_combobox(id, values, def, man) }
\ No newline at end of file |