var CONTEXTPATH = 'image/';//图片路径配置 var isIE = navigator.userAgent.toLowerCase().indexOf("msie") != -1; var isGecko = navigator.userAgent.toLowerCase().indexOf("gecko") != -1; function $(ele) { if (typeof(ele) == 'string'){ ele = document.getElementById(ele) if(!ele){ return null; } } if(ele){ Core.attachMethod(ele); } return ele; } function $T(tagName,ele){ ele = $(ele); ele = ele || document; var ts = ele.getElementsByTagName(tagName);//此处返回的不是数组 var arr = []; var len = ts.length; for(var i=0;i"; return str+">"+this.innerHTML+""; }); HTMLElement.prototype.__defineSetter__("innerText",function(sText){ var parsedText=document.createTextNode(sText); this.innerHTML=parsedText; return parsedText; }); HTMLElement.prototype.__defineGetter__("innerText",function(){ var r=this.ownerDocument.createRange(); r.selectNodeContents(this); return r.toString(); }); } var $E = {}; $E.getTopLevelWindow = function(){ var pw = window; while(pw!=pw.parent){ pw = pw.parent; } return pw; } $E.hide = function(ele) { ele = ele || this; ele = $(ele); ele.style.display = 'none'; } $E.show = function(ele) { ele = ele || this; ele = $(ele); ele.style.display = ''; } var Core = {}; Core.attachMethod = function(ele){ if(!ele||ele["$A"]){ return; } if(ele.nodeType==9){ return; } var win; try{ if(isGecko){ win = ele.ownerDocument.defaultView; }else{ win = ele.ownerDocument.parentWindow; } for(var prop in $E){ ele[prop] = win.$E[prop]; } }catch(ex){ //alert("Core.attachMethod:"+ele)//有些对象不能附加属性,如flash } } function Dialog(strID){ if(!strID){ alert("错误的Dialog ID!"); return; } this.ID = strID; this.isModal = true; this.Width = 400; this.Height = 300; this.Top = 0; this.Left = 0; this.ParentWindow = null; this.onLoad = null; this.Window = null; this.Title = ""; this.URL = null; this.DialogArguments = {}; this.WindowFlag = false; this.Message = null; this.MessageTitle = null; this.ShowMessageRow = false; this.ShowButtonRow = true; this.Icon = null; } Dialog._Array = []; Dialog.prototype.showWindow = function(){ if(isIE){ this.ParentWindow.showModalessDialog( this.URL, this.DialogArguments, "dialogWidth:" + this.Width + ";dialogHeight:" + this.Height + ";help:no;scroll:no;status:no") ; } if(isGecko){ var sOption = "location=no,menubar=no,status=no;toolbar=no,dependent=yes,dialog=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=no"; this.Window = this.ParentWindow.open( '', this.URL, sOption, true ) ; var w = this.Window; if ( !w ){ alert( "发现弹出窗口被阻止,请更改浏览器设置,以便正常使用本功能!" ) ; return ; } w.moveTo( this.Left, this.Top ) ; w.resizeTo( this.Width, this.Height+30 ) ; w.focus() ; w.location.href = this.URL ; w.Parent = this.ParentWindow; w.dialogArguments = this.DialogArguments; } } Dialog.prototype.show = function(){ var pw = $E.getTopLevelWindow(); var doc = pw.document; var cw = doc.compatMode == "BackCompat"?doc.body.clientWidth:doc.documentElement.clientWidth; var ch = doc.compatMode == "BackCompat"?doc.body.clientHeight:doc.documentElement.clientHeight;//必须考虑文本框处于页面边缘处,控件显示不全的问题 var sw = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft); var sh = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);//考虑滚动的情况 // alert("\n"+cw+"\n"+ch+"\n"+sw+"\n"+sh) if ( !this.ParentWindow ){ this.ParentWindow = window ; } this.DialogArguments._DialogInstance = this; this.DialogArguments.ID = this.ID; if(!this.Height){ this.Height = this.Width/2; } if(this.Top==0){ this.Top = (ch - this.Height - 30) / 2 + sh - 8; } if(this.Left==0){ this.Left = (cw - this.Width - 12) / 2 +sw; } if(this.ShowButtonRow){//按钮行高36 this.Top -= 18; } if(this.WindowFlag){ this.showWindow(); return; } var arr = []; arr.push(""); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push("
 "+this.Title+"
"); arr.push("
"); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push(" "); arr.push("
"); arr.push("
"); arr.push("
"); arr.push(" "); arr.push(" "); arr.push("
"); this.TopWindow = pw; var bgdiv = pw.$("_DialogBGDiv"); if(!bgdiv){ bgdiv = pw.document.createElement("div"); bgdiv.id = "_DialogBGDiv"; $E.hide(bgdiv); pw.$T("body")[0].appendChild(bgdiv); } var div = pw.$("_DialogDiv_"+this.ID); if(!div){ div = pw.document.createElement("div"); $E.hide(div); div.id = "_DialogDiv_"+this.ID; div.className = "dialogdiv"; div.setAttribute("dragStart","Dialog.dragStart"); pw.$T("body")[0].appendChild(div); } /*div.onmousedown = function(evt){ var w = $E.getTopLevelWindow(); //w.DragManager.onMouseDown(evt||w.event,this);//拖拽处理 }*/ this.DialogDiv = div; div.innerHTML = arr.join('\n'); pw.$("_DialogFrame_"+this.ID).DialogInstance = this; this.OKButton = pw.$("_ButtonOK_"+this.ID); this.CancelButton = pw.$("_ButtonCancel_"+this.ID); //显示标题图片 if(this.ShowMessageRow){ $E.show(pw.$("_MessageRow_"+this.ID)); if(this.MessageTitle){ pw.$("_MessageTitle_"+this.ID).innerHTML = this.MessageTitle; } if(this.Message){ pw.$("_Message_"+this.ID).innerHTML = this.Message; } } //显示按钮栏 if(!this.ShowButtonRow){ pw.$("_ButtonRow_"+this.ID).hide(); } if(this.OKEvent){ this.OKButton.onclick = this.OKEvent; } if(this.CancelEvent){ this.CancelButton.onclick = this.CancelEvent; } if(!this.AlertFlag){ $E.show(bgdiv); }else{ bgdiv = pw.$("_AlertBGDiv"); if(!bgdiv){ bgdiv = pw.document.createElement("div"); bgdiv.id = "_AlertBGDiv"; $E.hide(bgdiv); pw.$T("body")[0].appendChild(bgdiv); bgdiv.style.cssText = "background-color:#333;position:absolute;left:0px;top:0px;opacity:0.4;filter:alpha(opacity=40);width:" + cw + "px;height:" + ch + "px;z-index:991"; } } this.DialogDiv.style.cssText = "position:absolute; display:block;z-index:"+(this.AlertFlag?992:990)+";left:"+this.Left+"px;top:"+this.Top+"px"; //判断当前窗口是否是对话框,如果是,则将其置在bgdiv之后 if(!this.AlertFlag){ var win = window; var flag = false; while(win!=win.parent){//需要考虑父窗口是弹出窗口中的一个iframe的情况 if(win._DialogInstance){ win._DialogInstance.DialogDiv.style.zIndex = 959; flag = true; break; } win = win.parent; } if(!flag){ bgdiv.style.cssText = "background-color:#333;position:absolute;left:0px;top:0px;opacity:0.4;filter:alpha(opacity=40);width:" + cw + "px;height:" + ch + "px;z-index:960"; } } //放入队列中,以便于ESC时正确关闭 pw.Dialog._Array.push(this.ID); } Dialog.hideAllFlash = function(win){//非IE浏览器在对话框弹出时必须手工隐藏flash if(!win||!win.$T){//有可能是Dialog.alert() return; } var swfs = win.$T("embed"); for(var i=0;i "; var pw = $E.getTopLevelWindow(); pw.$("_DialogButtons_"+this.ID).$T("input")[0].getParent("a").insertAdjacentHTML("beforeBegin",html); pw.$("_Button_"+this.ID+"_"+id).onclick = func; } Dialog.close = function(evt){ window.Args._DialogInstance.close(); } Dialog.getInstance = function(id){ var pw = $E.getTopLevelWindow() var f = pw.$("_DialogFrame_"+id); if(!f){ return null; } return f.DialogInstance; } Dialog.AlertNo = 0; Dialog.alert = function(msg,func,w,h){ var pw = $E.getTopLevelWindow() var diag = new Dialog("_DialogAlert"+Dialog.AlertNo++); diag.ParentWindow = pw; diag.Width = w?w:300; diag.Height = h?h:120; diag.Title = "系统提示"; diag.URL = "javascript:void(0);"; diag.AlertFlag = true; diag.CancelEvent = function(){ diag.close(); if(func){ func(); } }; diag.show(); pw.$("_AlertBGDiv").show(); $E.hide(pw.$("_ButtonOK_"+diag.ID)); var win = pw.$("_DialogFrame_"+diag.ID).contentWindow; var doc = win.document; doc.open(); doc.write("") ; var arr = []; arr.push(""); arr.push(""); arr.push("
"+msg+"
"); var div = doc.createElement("div"); div.innerHTML = arr.join(''); doc.body.appendChild(div); doc.close(); var h = Math.max(doc.documentElement.scrollHeight, doc.body.scrollHeight); var w = Math.max(doc.documentElement.scrollWidth, doc.body.scrollWidth); if(w>300){ win.frameElement.width = w; } if(h>120){ win.frameElement.height = h; } diag.CancelButton.value = "确 定"; pw.$("_DialogButtons_"+diag.ID).style.textAlign = "center"; } Dialog.confirm = function(msg,func1,func2,w,h){ var pw = $E.getTopLevelWindow() var diag = new Dialog("_DialogAlert"+Dialog.AlertNo++); diag.Width = w?w:300; diag.Height = h?h:120; diag.Title = "信息确认"; diag.URL = "javascript:void(0);"; diag.AlertFlag = true; diag.CancelEvent = function(){ if(func2){ func2(); } diag.close(); }; diag.OKEvent = function(){ if(func1){ func1(); } diag.close(); }; diag.show(); pw.$("_AlertBGDiv").show(); var win = pw.$("_DialogFrame_"+diag.ID).contentWindow; var doc = win.document; doc.open(); doc.write("") ; var arr = []; arr.push(""); arr.push(""); arr.push("
"+msg+"
"); var div = doc.createElement("div"); div.innerHTML = arr.join(''); doc.body.appendChild(div); doc.close(); pw.$("_DialogButtons_"+diag.ID).style.textAlign = "center"; } var _DialogInstance = window.frameElement?window.frameElement.DialogInstance:null; var Page={}; Page.onDialogLoad = function(){ if(_DialogInstance){ if(_DialogInstance.Title){ document.title = _DialogInstance.Title; } window.Args = _DialogInstance.DialogArguments; _DialogInstance.Window = window; window.Parent = _DialogInstance.ParentWindow; } } Page.onDialogLoad(); PageOnLoad=function (){ var d = _DialogInstance; if(d){ try{ d.ParentWindow.$D = d; d.ParentWindow.$DW = d.Window; var flag = false; if(!this.AlertFlag){ var win = d.ParentWindow; while(win!=win.parent){ if(win._DialogInstance){ flag = true; break; } win = win.parent; } if(!flag){ $E.getTopLevelWindow().$("_DialogBGDiv").style.opacity="0"; $E.getTopLevelWindow().$("_DialogBGDiv").style.filter="alpha(opacity=0)"; } } if(d.AlertFlag){ $E.show($E.getTopLevelWindow().$("_AlertBGDiv")); } if(d.ShowButtonRow&&$E.visible(d.CancelButton)){ d.CancelButton.focus(); } if(d.onLoad){ d.onLoad(); } }catch(ex){alert("DialogOnLoad:"+ex.message+"\t("+ex.fileName+" "+ex.lineNumber+")");} } } Dialog.onKeyUp = function(event){ if(event.keyCode==27){ var pw = $E.getTopLevelWindow(); if(pw.Dialog._Array.length>0){ //Page.mousedown(); //Page.click(); var diag = pw.Dialog.getInstance(pw.Dialog._Array[pw.Dialog._Array.length-1]); diag.CancelButton.onclick.apply(diag.CancelButton,[]); } } }; Dialog.dragStart = function(evt){ //DragManager.doDrag(evt,this.getParent("div"));//拖拽处理 } //按ESC关闭对话框 if(isIE){ document.attachEvent("onkeyup",Dialog.onKeyUp); window.attachEvent("onload",PageOnLoad); }else{ document.addEventListener("keyup",Dialog.onKeyUp,false); window.addEventListener("load",PageOnLoad,false); }