asp的bbs程序
源代码在线查看: combobox.lib.js
/*
By Hangring
#2008.02.02#
---
use list:
> node.lib.js
> events.lib.js
> css.lib.js
> panel.lib.js
> contorls/list.lib.js
---
拾色器
---
包含样式:
*/
function ComboBox () {
this.container = null;
// data
this.data = [];
this.selectedIndex = -1;
this.selectedLabel = '';
this.selectedData = '';
// text field save selected label
this.textField = null;
this.name = 'combobox_' + Math.random();
// editabel or not
this.editable = false;
this.list = new List();
this.isCreate = false;
// contain the list object
this.panel = null;
// panel is display or not
this.panelDisplay = false;
this.css = {
combobox:'combobox',
textfield_container:'textfield-container',
textfield:'textfield'
};
}
ComboBox.prototype.Init = function () {
};
ComboBox.prototype.Create = function () {
var self = this;
var container = this.container = oNode.CreateNode('div');
CSS.AddClass(container, this.css.combobox);
var containerIn = oNode.CreateNode('div');
oNode.AddNode(containerIn, container);
CSS.AddClass(containerIn, this.css.textfield_container);
var textField = this.textField = oNode.CreateNode('input');
oNode.AddNode(textField, containerIn);
CSS.AddClass(textField, this.css.textfield);
textField.type = 'text';
textField.readOnly = !this.editable;
textField.name = this.name;
textField.value = '';
var list = this.list;
list.multiple = true;
list.data = self.data;
list.Change = function () {
self._Change();
};
list.Create();
this._Change();
Events.AttachEvent(container, 'click', function () {
if (!self.isCreate) {
self.isCreate = true;
var panel = self.panel = PopUp.Panel(list.container);
PopUp.AddPopUp(panel);
PopUp.AddMask(panel);
var x = Global.GetOffsetLeft(container) + 'px';
var y = Global.GetOffsetTop(container) + container.offsetHeight + 'px';
PopUp.SetXY(panel, x, y);
Events.AttachEvent(document, 'mousedown', function (e) {
var obj = $EO(e);
while (obj) {
if (obj == container) return;
obj = obj.parentNode;
}
self.SetVisible(false);
});
}
self.list._MoveChange(self.selectedIndex);
self.SetVisible(!self.panelDisplay);
});
return container;
};
// 设置显示隐藏
ComboBox.prototype.SetVisible = function (visible /* :Boolean */) {
this.panelDisplay = visible;
PopUp.SetVisible(this.panel, visible);
}
ComboBox.prototype._Change = function () {
this.selectedIndex = this.list.selectedIndex;
this.selectedLabel = this.list.selectedLabel;
this.selectedData = this.list.selectedData;
this.textField.value = this.selectedLabel;
this.Change();
};
ComboBox.prototype.Change = function () {
};