Global_run_event_hook = true;
Global_combo_array = new Array();
ComboBox = function()
{
if(arguments.length==0)
{
self.status="ComboBox invalid - no name argument";
}
this.name = arguments[0];
// var bodyRef = document.getElementById("docBody");
// var documentElementRef = bodyRef.getElementById(arguments[1]);
// this.parent = documentElementRef || document.body;
this.parent = arguments[1] || document.body;
this.constBaseDivSuffix = "_base";
this.constListDivSuffix = "_list";
this.constInputSuffix = "_input";
this.constHiddenSuffix = "_hidden";
this.options = new Array();
this.expops = new Array();
this.value = "";
this.onChangeSelected = null;
this.view = this.createBase();
Global_combo_array[Global_combo_array.length]=this;
if(Global_run_event_hook){this.init(this)}
}
// detect a special case of "web browser"
ComboBox.is_ie = ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) );
ComboBox.is_ie5 = ( ComboBox.is_ie && /msie 5\.0/i.test(navigator.userAgent) );
// detect Opera browser
ComboBox.is_opera = /opera/i.test(navigator.userAgent);
// detect KHTML-based browsers
ComboBox.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
// detect Firefox browser
ComboBox.is_firefox = /Firefox/i.test(navigator.userAgent);
ComboBox.prototype.getControlName = function(suffix)
{
return this.name + suffix;
}
ComboBox.prototype.getControl = function(suffix)
{
return document.getElementById(this.getControlName(suffix));
}
ComboBox.prototype.createBase = function()
{
var div = document.createElement("div");
div.name = this.name + this.constBaseDivSuffix;
div.id = this.name + this.constBaseDivSuffix;
div.innerHTML = "
";
this.parent.appendChild(div);
this.valcon = this.getControl(this.constHiddenSuffix);
this.txtview = this.getControl(this.constInputSuffix);
return div;
}
ComboBox.prototype.choose = function(realval,txtval)
{
this.value = realval;
var samstring = this.name+".txtview.value='"+txtval+"'";
window.setTimeout(samstring,1);
this.valcon.value = realval;
if (this.onChangeSelected) {this.onChangeSelected(this.value);}
}
Array.prototype.remove=function(dx)
{
if(isNaN(dx)||dx>this.length){self.status='Array_remove:invalid request-'+dx;return false;}
for(var i=0,n=0;i 0)
{
return this.options[0];
}
else
{
return null;
}
}
ComboBox.prototype.setValue = function(value, raise)
{
var item = this.getItem(value);
if (item != null)
{
this.value = item.value;
this.valcon.value = item.value;
this.txtview.value = item.text;
}
else
{
this.value = -1;
this.valcon.value = -1;
this.txtview.value = "";
}
if (raise && this.onChangeSelected) {this.onChangeSelected(this.value);}
}
ComboBox.prototype.mouseDown = function(e)
{
var current, el;
el = e.target ? e.target : e.srcElement;
/* Определяем в каких границах нажали кнопку */
var element = this.getDIV(el);
/* Если в граница основного элемента или выпадающего списка, то ничего не делаем */
if (element == this.opslist || element == this.view)
{
return;
}
/* Пробегаем весь список элементов и закрываем у них выпадающий список */
for(i=0;i' +
' '+arr[i].text+' | ' +
'';
}
str = str + strs.join("") + '';
if(this.opslist){this.view.removeChild(this.opslist);}
this.opslist = document.createElement("DIV");
this.opslist.name = this.name + this.constListDivSuffix;
this.opslist.id = this.name + this.constListDivSuffix;
this.opslist.innerHTML=str;
this.opslist.style.position='absolute';
this.opslist.style.display='none';
this.opslist.className = "e-combo-list";
this.opslist.onselectstart = ComboBox.returnFalse;
this.opslist.style.width = this.view.clientWidth + "px";
this.view.appendChild(this.opslist);
}
ComboBox.prototype.toggle = function()
{
if(this.opslist)
{
if(this.opslist.style.display=="block")
{
this.opslist.style.display="none";
}
else
{
this.update();
this.build(this.options);
this.view.style.zIndex = ++ComboBox.prototype.COMBOBOXZINDEX;
this.opslist.style.display="block";
}
}
else
{
this.update();
this.build(this.options);
this.view.style.zIndex = ++ComboBox.prototype.COMBOBOXZINDEX;
this.opslist.style.display="block";
}
}
ComboBox.prototype.COMBOBOXZINDEX = 1000 //change this if you must
ComboBox.prototype.init = function(control)
{
if (document.addEventListener)
{
document.addEventListener("keyup", function(e){control.handleKey(e)}, false );
document.addEventListener("mousedown", function(e){control.mouseDown(e)}, false );
}
else if (document.attachEvent)
{
document.attachEvent("onkeyup", function () { control.handleKey(window.event); } );
document.attachEvent("onmousedown", function () { control.mouseDown(window.event); } );
}
/* Чтобы другой контрол не садился второй раз на эти же события */
//Global_run_event_hook = false;
}
/* Конструктор, элемент списка */
ComboBoxItem = function(text,value)
{
this.text = text;
this.value = value;
}
/* Пустой обработчик события */
ComboBox.returnFalse = function()
{
return false;
}
ComboBox.prototype.clearItems = function()
{
this.options = new Array();
}
ComboBox.prototype.renderItems = function(array, valueProperty, nameProperty)
{
this.clearItems();
if (array == null){return;}
for (var i=0;i