//Popup class 显示弹出窗口,简单整理了一下。
/*
// 示例用法
function ShowIframe() //显示iframe
{
var pop=new Popup({ contentType:1,isReloadOnClose:false,width:400,height:500});
pop.setContent("contentUrl","www.baidu");
pop.setContent("title","框架iframe示例");
pop.build();
pop.show();
}
function ShowHtmlString() //显示html
{
var strHtml = "<table border=1 style='width:90%; text-align:center;'><tr style='height:40px'><td>ds</td><td>dads</td></tr><tr style='height:40px'><td>dadas</td><td>dasd</td></tr><tr style='height:40px'><td>dadasd</td><td>dsadads</td></tr></table>";
var pop=new Popup({ contentType:2,isReloadOnClose:false,width:340,height:300});
pop.setContent("contentHtml",strHtml);
pop.setContent("title","字符串示例html");
pop.build();
pop.show();
}
function ShowAlert() //显示警示对话框
{
var pop=new Popup({ contentType:4,isReloadOnClose:true,width:340,height:80});
pop.setContent("title","警告框示例alert");
pop.setContent("alertCon","alert对话框的内容");
pop.build();
pop.show();
}
function ShowConfirm() //显示确认对话框
{
var pop=new Popup({ contentType:3,isReloadOnClose:false,width:340,height:80});
pop.setContent("title","对话框示例confirm");
pop.setContent("confirmCon","confirm对话框的内容");
pop.setContent("callBack",ShowCallBack); //回调函数
pop.setContent("parameter",{id:"divCall",str:"点击确定后显示的字符串",obj:pop});
pop.build();
pop.show();
}
function ShowCallBack(para) //回调函数
{
var o_pop = para["obj"]
var obj = ElementById(para["id"]);
o_pop.close();
obj.innerText = para["str"];
}
*/
if(!Array.prototype.push){
Array.prototype.push=function(){
var startLength=this.length;
for(var i=0;i<arguments.length;i++)
this[startLength+i]=arguments[i];
return this.length;
}
};
function G(){
var elements=new Array();
for(var i=0;i<arguments.length;i++){
var element=arguments[i];
if(typeof element=='string')
ElementById(element);
if(arguments.length==1)
return element;elements.push(element)
};
return elements
};
Function.prototype.bind=function(object){
var __method=this;
return function(){__method.apply(object,arguments)}
};
Function.prototype.bindAsEventListener=function(object){
var __method=this;
return function(event){__method.call(object,event||window.event)}
};
for(prope
rty in source){destination[property]=source[property]};return destination
};
if(!window.Event){var Event=new Object()};
if(element.attachEvent){this.observers.push([element,name,observer,useCapture]);element.attachEvent('on'+name,observer)}},unloadCache:function(){if(!Event.observers)return;for(var i=0;i<Event.observers.length;i++){Event.stopObserving.apply(this,Event.observers[i]);Event.observers[i][0]=null};Event.observers=false},observe:function(element,name,observer,useCapture){var element=G(element);useCapture=useCapture||false;if(name=='keypress'&&(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.attachEvent))name='keydown';this._observeAndCache(element,name,observer,useCapture)},stopObserving:function(element,name,observer,useCapture){var element=G(element);useCapture=useCapture||false;if(name=='keypress'&&(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.detachEvent))name='keydown';veEventListener){veEventListener(name,observer,useCapture)}else if(element.detachEvent){element.detachEvent('on'+name,observer)}}});
Event.observe(window,'unload',Event.unloadCache,false);
var(){
var _class=function(){
this.initialize.apply(this,arguments)
};
for(i=0;i<arguments.length;i++){
superClass=arguments[i];for(member in superClass.prototype){_class.prototype[member]=superClass.prototype[member]}
};
_class.child=function(){return new Class(this)};
_d=function(f){for(property in f){_class.prototype[property]=f[property]}};
return _class
};
function space(flag){
if(flag=="begin"){
var ElementById("ft");
if(typeof(ele)!="undefined"&&ele!=null)
ele.id="ft_popup";
ElementById("usrbar");
if(typeof(ele)!="undefined"&&ele!=null)
ele.id="usrbar_popup"
}
else if(flag=="end"){
var ElementById("ft_popup");
if(typeof(ele)!="undefined"&&ele!=null)ele.id="ft";
ElementById("usrbar_popup");
if(typeof(ele)!="undefined"&&ele!=null)ele.id="usrbar"}
};
// Popup
var Popup=new Class();
Popup.prototype={
iframeIdName:'ifr_popup', //iframe的名字
initialize:function(config){
contentType:1, //pop类型 1. 内嵌iframe,2. 显示给定的html 3. confirm框 4. alert框
isHaveTitle:true, //是否有标题栏
scrollType:'no', //内嵌iframe是否可以滚动
isBackgroundCanClick:false,  //是否需要遮罩,false为不能被点击需要遮罩
isSupportDraging:true, //是否支持拖动
isShowShadow:true, //是否显示阴影
isReloadOnClose:true, //关闭后是否重新加载页面
width:400, //宽度
height:300 //高度
},config||{});
this.info={ //参数
shadowWidth:4, //阴影宽度
title:"", //标题
contentUrl:"", //iframe的url
contentHtml:"", //内容的html
callBack:null, //回调函数
parameter:null, //调用的参数 如 {id:"divCall",str:"点击确定后显示的字符串",obj:pop}
confirmCon:"", //confirm的内容
alertCon:"", //alert的内容
someHiddenTag:"select,object,embed", //自动隐藏的页面元素
someDisabledBtn:"", //禁用的btn
someHiddenEle:"", //隐藏的匀速
overlay:0, //覆盖
coverOpacity:40 //蒙皮不透明度
};
cColor:"#EEEEEE", //蒙皮颜
bColor:"#FFFFFF", //背景颜
tColor:"#48BBFA", //标题背景颜,边框颜
wColor:"#FFFFFF" //标题文字颜
};
this.dropClass=null;
this.someToHidden=[];
this.someToDisabled=[];
if(!fig.isHaveTitle)
this.iniBuild()box shadow怎么设置
},
setContent:function(arrt,val){ //设置内容,即 this.info 的参数内容
if(val!=''){
switch(arrt){
case 'width':fig.width=val;break;
case 'height':fig.height=val;break;
case 'title':this.info.title=val;break;
case 'contentUrl':tUrl=val;break;
case 'contentHtml':tHtml=val;break;
case 'callBack':this.info.callBack=val;break;
case 'parameter':this.info.parameter=val;break;
case 'confirmCon':firmCon=val;break;
case 'alertCon':this.info.alertCon=val;break;
case 'someHiddenTag':this.info.someHiddenTag=val;break;
case 'someHiddenEle':this.info.someHiddenEle=val;break;
case 'someDisabledBtn':this.info.someDisabledBtn=val;break;
case 'overlay':this.info.overlay=val}
}
},
iniBuild:function(){
G('dialogCase')?G('dialogCase').veChild(G('dialogCase')):function(){};
var ateElement('span');oDiv.id='dialogCase';document.body.appendChild(oDiv)
},
build:function(){
var baseZIndex=10001+this.info.overlay*10;
var showZIndex=baseZIndex+2;this.iframeIdName='ifr_popup'+this.info.overlay;
//关
闭按钮
//var path="img.baidu/hi/img/";
//var close='<input type="image" id="dialogBoxClose" src="'+path+'dialogclose.gif" border="0" width="16" height="16" align="absmiddle" title="关闭"/>';
var close='<a id="dialogBoxClose" title="关闭" >×</a>';
var cB='filter: alpha(opacity='+verOpacity+');opacity:'+verOpacity/100+';';
var cover='<div id="dialogBoxBG" ></div>';
var mainBox='<div id="dialogBox" ><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="'+lor.bColor+'">';fig.isHaveTitle){mainBox+='<tr height="24" bgcolor="'+lor.tColor+'"><td><table width="100%" border="0" cellpadding="0" cellspacing="0" ><tr>'+'<td width="6" height="24"></td><td id="dialogBoxTitle" >'+this.info.title+' </td>'+'<td id="dialogClose" width="20" align="right" valign="middle">'+close+'</td><td width="6"></td></tr></table></td></tr>'}
else{mainBox+='<tr height="10"><td align="right">'+close+'</td></tr>'};
mainBox+='<tr valign="top"><td id="dialogBody" ></td></tr></table></div>'+'<div id="dialogBoxShadow" ></div>';
if(!fig.isBackgroundCanClick){G('dialogCase').innerHTML=cover+mainBox;G('dialogBoxBG').style.height=document.body.scrollHeight}
else G('dialogCase').innerHTML=mainBox;Event.observe(G('dialogBoxClose'),"click",set.bindAsEventListener(this),false);
fig.isSupportDraging){dropClass=new fig.fig.height,this.info.fig.tType);G("dialogBoxTitle").style.cursor="move"};this.lastBuild()},lastBuild:function(){var confirm='<div ><div >'+firmCon+'</div><div ><input id="dialogOk" type="button" value=" 确定 "/> <input id="dialogCancel" type="button" value=" 取消 "/></div></div>';
var alert='<div ><div >'+this.info.alertCon+'</div><div ><input id="dialogYES" type="button" value=" 确定 "/></div></div>';
var baseZIndex=10001+this.info.overlay*10;var coverIfZIndex=baseZIndex+4;
tType==1){var openIf
rame="<iframe width='100%' style='height:"+fig.height+"px' name='"+this.iframeIdName+"' id='"+this.iframeIdName+"' src='"+tUrl+"' frameborder='0' scrolling='"+fig.scrollType+"'></iframe>";
var coverIframe="<div id='iframeBG' style='position:absolute;top:0px;left:0px;width:1px;height:1px;z-index:"+coverIfZIndex+";filter: alpha(opacity=00);opacity:0.00;background-color:#ffffff;'><div>";G("dialogBody").innerHTML=openIframe+coverIframe}
else tType==2){G("dialogBody").innerHTML=tHtml}else tType==3){G("dialogBody").innerHTML=confirm;Event.observe(G('dialogOk'),"click",this.forCallback.bindAsEventListener(this),false);
Event.observe(G('dialogCancel'),"click",this.close.bindAsEventListener(this),false)}else tType==4){G("dialogBody").innerHTML=alert;Event.observe(G('dialogYES'),"click",this.close.bindAsEventListener(this),false)}},reBuild:function(){G('dialogBody').height=G('dialogBody').clientHeight;this.lastBuild()},show:function(){this.hiddenSome();this.middle();fig.isShowShadow)this.shadow()},forCallback:function(){return this.info.callBack(this.info.parameter)},shadow:function(){var oShadow=G('dialogBoxShadow')
;var oDialog=G('dialogBox');oShadow['style']['position']="absolute";oShadow['style']['background']="#000";oShadow['style']['display']="";oShadow['style']['opacity']="0.2";oShadow['style']['filter']="alpha(opacity=20)";oShadow['style']['top']=oDialog.offsetTop+this.info.shadowWidth;oShadow['style']['left']=oDialog.offsetLeft+this.info.shadowWidth;oShadow['style']['width']=oDialog.offsetWidth;oShadow['style']['height']=oDialog.offsetHeight},middle:function(){if(!fig.isBackgroundCanClick)G('dialogBoxBG').style.display='';
var oDialog=G('dialogBox');
oDialog['style']['position']="absolute";
oDialog['style']['display']='';
//取得页面的宽度和高度
var sClientWidth=document.body.clientWidth;
var sClientHeight=document.body.clientHeight;
var sScrollTop=document.body.scrollTop;
//
var sleft=(sClientWidth/2)-(oDialog.offsetWidth/2);
var iTop=-80+(sClientHeight/2+sScrollTop)-(oDialog.offsetHeight/2);
var sTop=iTop>0?iTop:(sClientHeight/2+sScrollTop)-(oDialog.offsetHeight/2);
if(sTop<1)sTop="20";if(sleft<1)sleft="20";
oDialog['style']['left']=sleft+"px"; //左侧位置
oDialog['style']['top']=sTop+"px"    //顶部位置
},
reset:function(){fig.isReloadOnClose){load()};this.close()},close:function(){G('dialogBox').style.display='none';
if(!fig.isBackgroundCanClick)G('dialogBoxBG').style.display='none';
fig.isShowShadow)G('dialogBoxShadow').style.display='none';G('dialogBody').innerHTML='';
this.showSome()},hiddenSome:function(){var tag=this.info.someHiddenTag.split(",");
if(tag.length==1&&tag[0]=="")tag.length=0;
for(var i=0;i<tag.length;i++){this.hiddenTag(tag[i])};
var ids=th

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。