summaryrefslogtreecommitdiffhomepage
path: root/libs/cbi/htdocs/luci-static/resources/cbi.js
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cbi/htdocs/luci-static/resources/cbi.js')
-rw-r--r--libs/cbi/htdocs/luci-static/resources/cbi.js73
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