function JSCombo(name, data) {
this.active = 1;
this.last_value = null;
this.debug2_lines = 10;
this.name = name;
this.myfilter = new BFilter(data);
this.myfilter.timeout = 0;
this.myfilter.parentclass = this;
eval("this.myfilter.result = function (arr) { var el = this.element_id('" + this.name + "'+'sel'); el.options[el.options.length] = new Option(arr[1],arr[2]); return true; }");
eval("this.myfilter.clear_results = function () { var el = this.element_id('" + this.name + "' + 'sel'); this.parentclass.active = 0; el.style.display = 'none'; el.options.length = 0; el.selectedIndex = -1; return true;}");
eval("this.myfilter.show_results = function () { var el_textbox = this.element_id('" + this.name + "textfilter'); var el_dropdown = this.element_id('" + this.name + "sel'); el_dropdown.style.display = ''; this.parentclass.last_value = el_textbox.value; return true;}");
var el_textbox = this.myfilter.element_id(this.name + 'textfilter');
el_textbox.focus();
el_textbox.caretPos=1;
// el_textbox.select();
}
JSCombo.prototype.debug2 = function (text) {
var el = this.myfilter.element_id('debug2',1);
if (! el) return;
this.debug2_lines++;
if (this.debug2_lines > 10) {
el.innerHTML = "...
";
this.debug2_lines = 0;
}
if (el) el.innerHTML += this.debug2_lines+": "+text+"
";
return true;
}
// keypress in dropdown
JSCombo.prototype.dropdown_keydown = function (event) {
var d = event.keyCode;
this.debug2("dropdown key: "+d);
var el_textbox = this.myfilter.element_id(this.name + 'textfilter');
var el_sel = this.myfilter.element_id(this.name + 'sel');
// return to textbox and hide results on
// enter, backspace, left, right, esc
if (d == 13 || d == 8 || d == 37 || d == 39 || d == 27) {
el_textbox.focus();
this.myfilter.clear_results();
// ignore backspace (to prevent back in history)
if (d == 8) return false;
if (d == 27) {
el_textbox.value = this.last_value;
}
}
// up or down on first/last element?
var sel = el_sel.selectedIndex;
var max = el_sel.options.length - 1;
this.debug2("selected: "+sel+" max: "+max);
if ( (d == 38 && sel == 0) || (d == 40 && sel == max) ) {
this.myfilter.clear_results();
el_textbox.value = this.last_value;
el_textbox.focus();
this.active = 0;
}
return true;
}
// keypress in textbox
JSCombo.prototype.textbox_keydown = function (e) {
var d = e.keyCode;
this.debug2("textbox key: "+d);
var el = this.myfilter.element_id(this.name + 'sel');
if (! el) return false;
this.active = 0;
var el_textbox = this.myfilter.element_id(this.name + 'textfilter');
var el_sel = this.myfilter.element_id(this.name + 'sel');
// up, down -- go to dropdown
if ((d == 40)) {
// filter if no results
this.debug2("existing results: "+el_sel.options.length);
if (el_sel.options.length <= 0) {
this.myfilter.show_filter(el_textbox.value);
} else {
this.myfilter.show_results();
el_sel.focus();
}
return false;
}
// if not enter, show combo
if (d != 13) this.active = 1;
// if (this.last_value == el_textbox.value) this.active = 0;
// left, right -- hide dropdown
if ((d == 37) || (d == 39)) {
this.myfilter.clear_results();
return false;
}
return true;
}
JSCombo.prototype.filter = function(value) {
this.debug2("combo filter: "+value+" ["+this.active+"]");
if (! this.active) {
return null;
}
return this.myfilter.filter(value);
}