/**
* wangyuqiu@2009-04-10
*/
/**
* divWindow 对象
* 需要结合jquery使用
*/
function divWindow(windowId){
if(windowId)
this.id = windowId;
else
return null;
this.status = 0;
this.height = 300;
this.width = 400;
//debugger;
if($("#"+this.id).length == 0){
this.divNode = $("<div />");
this.divNode.attr({id:this.id});
this.divNode.attr({"class":"divWindow"});
this.backGroundDiv = $("<div />");
this.backGroundDiv.attr({id:this.id+"_BackGroundDiv"});
this.backGroundDiv.attr({"class":"outDivWindow"});
this.divNode.appendTo("body");
this.backGroundDiv.appendTo("body");
}else{
this.divNode = $("#"+this.id).eq(0);
this.backGroundDiv = $("#"+this.id+"_BackGroundDiv").eq(0);
}
}
/**
* 设置divWindow 的内容
*/
divWindow.prototype.set = function(node){
if(this.divNode.html() == ""){
if(typeof node === "string")
this.divNode.append($(node));
else if(typeof node === "object")
this.divNode.append(node);
else
alert("非法参数!");
}
}
/**
* divWindow 展示函数
*/
divWindow.prototype.show = function(){
//debugger;
this.divNode.height(this.height);
this.divNode.width(this.width);
var windowWidth = document.body.clientWidth;
var windowHeight = document.body.clientHeight;
var popupHeight = this.divNode.height();
var popupWidth = this.divNode.width();
this.divNode.css({
"position": "absolute",
"top": windowHeight/2-popupHeight/2,
"left": windowWidth/2-popupWidth/2
});
//this.backGroundDiv.css({
// "height": windowHeight
//});
//show
if(this.status==0){
this.backGroundDiv.css({
"opacity": "0.7",
"width":windowWidth,
"height":windowHeight
});
this.backGroundDiv.fadeIn("fast");
this.divNode.fadeIn("fast",this.beforeShow);
this.status = 1;
}
}
/**
* divWindow 关闭函数
*/
divWindow.prototype.close = function(){
if(this.status==1){
this.backGroundDiv.fadeOut("fast");
this.divNode.fadeOut("fast",this.beforeClose);
this.status = 0;
}
}
/**
* divWindow 展示前的回调
*/
divWindow.prototype.beforeShow = function( _func){
if ((!!_func)&&(typeof _func == "function"))
this.beforeShow = _func;
}
/**
* divWindow 关闭之前的回调
*/
divWindow.prototype.beforeClose = function( _func){
if ((!!_func)&&(typeof _func == "function"))
this.beforeClose = _func;
}