dropdown.js
Summary
No overview generated for 'dropdown.js'
Zapatec.DropDown = function(objArgs){
if(arguments.length == 0){
objArgs = {};
}
Zapatec.DropDown.SUPERconstructor.call(this, objArgs);
}
Zapatec.inherit(Zapatec.DropDown, Zapatec.Widget);
Zapatec.DropDown.prototype.init = function(objArgs){
this.config.element = null;
this.config.hook = null;
this.config.onselect = null;
Zapatec.DropDown.SUPERclass.init.call(this, objArgs);
if(typeof(this.config.element) == 'string'){
this.config.element = document.getElementById(this.config.element);
}
if(this.config.element == null){
throw "No target element given";
}
this.container = null;
this.table = null;
this.header = null;
this.body = null;
this.content = {};
var self = this;
if(this.config.hook){
Zapatec.Utils.addEvent(this.config.hook, 'click', function(){self.isVisible = true;});
}
Zapatec.Utils.addEvent(document, 'keypress', function(e) {
if (!e){
e = window.event;
}
if (e.keyCode == 27){
self.hide();
}
});
Zapatec.Utils.addEvent(document, 'click', function(e) {
if(!self.isVisible){
self.hide();
}
self.isVisible = false;
});
}
Zapatec.DropDown.prototype.getContainer = function(){
return this.container;
}
Zapatec.DropDown.prototype.setContent = function(objSource){
if(objSource == null){
return null;
}
this.content = objSource;
}
Zapatec.DropDown.prototype.show = function(){
if(this.container != null){
this.hide();
}
this.isVisible = false;
this.container = Zapatec.Utils.createElement("div");
this.container.className = this.getClassName({prefix: "zpDropDown", suffix: "Container"})
this.container.style.position = 'absolute';
this.container.style.display = 'none';
this.table = Zapatec.Utils.createElement("table");
this.table.border = 0;
this.table.cellSpacing = 0;
this.container.appendChild(this.table);
this.container.style.zIndex = Zapatec.Utils.getMaxZindex();
var self = this;
this.container.onclick = function(){self.isVisible = true;}
this.header = this.table.appendChild(document.createElement("thead"));
this.body = this.table.appendChild(document.createElement("tbody"));
document.body.appendChild(this.container);
this.fillRows();
var pos = Zapatec.Utils.getElementOffset(this.config.element);
this.container.style.left = pos.x + "px";
this.container.style.top = (pos.y + this.config.element.offsetHeight) + "px";
this.container.style.visibility = "hidden";
this.container.style.display = 'block';
this.table.width = "";
var oldTableWidth = this.table.scrollWidth;
this.container.style.width = this.table.scrollWidth + "px";
this.table.width = "100%";
if(this.container.clientHeight > 200){
var scrollEl = Zapatec.is_gecko ? this.body : this.container;
scrollEl.className += " " + this.getClassName({prefix: "zpDropDown", suffix: "Overflowed"});
var wid = (2*scrollEl.scrollWidth - scrollEl.clientWidth) + "px";
this.container.style.width = wid;
this.table.width = wid;
}
this.WCH = Zapatec.Utils.createWCH();
if(this.WCH){
Zapatec.Utils.setupWCH(this.WCH, parseInt(this.container.style.left), parseInt(this.container.style.top), this.container.clientWidth, this.container.clientHeight);
this.WCH.style.zIndex = this.container.style.zIndex - 1;
}
this.container.style.visibility = "";
}
Zapatec.DropDown.prototype.hide = function(){
if(this.container != null){
Zapatec.Utils.destroy(this.container);
this.container = null;
if(this.WCH){
Zapatec.Utils.destroy(this.WCH);
}
}
}
Zapatec.DropDown.prototype.clear = function(){
if(this.header != null){
for(var ii = this.header.childNodes.length - 1; ii >= 0 ; ii--){
this.header.removeChild(this.header.childNodes[ii]);
}
}
if(this.body != null){
for(var ii = this.body.childNodes.length - 1; ii >= 0 ; ii--){
this.body.removeChild(this.body.childNodes[ii]);
}
}
}
Zapatec.DropDown.prototype.fillRows = function(){
this.clear();
var tr = null;
var td = null;
if(
this.content.header != null &&
this.content.header.length > 0
){
tr = this.header.appendChild(document.createElement("tr"));
tr.className = "dropDownHeader";
for(var ii = 0; ii < this.content.header.length; ii++){
var col = this.content.header[ii];
td = tr.appendChild(document.createElement("td"));
if(col.className != null){
td.className = col.className
}
if(col.style != null){
Zapatec.Utils.applyStyle(td, col.style);
}
td.appendChild(document.createElement("span")).innerHTML = col.name;
}
}
var colspan = 1;
if(
this.content.header != null
){
colspan = this.content.header.length;
} else if(this.content.body != null){
colspan = this.content.body[0].length;
}
if(
this.content.body == null ||
this.content.body.length == 0
){
tr = this.header.appendChild(document.createElement("tr"));
td = tr.appendChild(document.createElement("td"));
td.className = "noRecords";
td.colSpan = colspan;
td.appendChild(document.createTextNode("No records!"))
} else {
var isOdd = false;
for(var ii = 0; ii < this.content.body.length; ii++){
tr = this.body.appendChild(document.createElement("tr"));
tr.style.width = "100%"
tr.className = "dropDown" + ((isOdd = !isOdd) ? "Odd" : "Even");
var self = this;
tr.onclick = new Function("var self = Zapatec.Widget.all['" + this.id + "']; self.selectValue(" + ii + "); return true;")
if(Zapatec.is_ie){
tr.onmouseover = function(){this.className += ' dropDownHighlighted'}
tr.onmouseout = function(){this.className = this.className.replace(' dropDownHighlighted', "")}
}
for(var jj = 0; jj < this.content.body[ii].length; jj++){
td = tr.appendChild(document.createElement("td"));
if(
this.content.header != null &&
this.content.header[jj] != null
){
if(this.content.header[jj].colStyle != null){
Zapatec.Utils.applyStyle(td, this.content.header[jj].colStyle);
}
if(this.content.header[jj].colClassName != null){
td.className = this.content.header[jj].colClassName;
}
}
td.appendChild(document.createElement("span")).innerHTML = this.content.body[ii][jj];
}
}
}
}
Zapatec.DropDown.prototype.selectValue = function(currentRow){
if(
this.config.onselect != null &&
this.content != null &&
currentRow < this.content.body.length
){
this.config.onselect(this.content.body[currentRow])
this.hide();
}
}
Zapatec.DropDown.prototype.setWidth = function(width){
width = parseInt(width);
if(isNaN(width)){
return false;
}
this.container.style.width = width + "px";
this.table.style.width = width + "px";
}
Documentation generated by
JSDoc on Thu Apr 5 19:15:07 2007