zDialog.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /**
  2. * zDialog 2.0
  3. * 最后修正:2009-12-18
  4. **/
  5. var IMAGESPATH = 'zDialog/images/'; //图片路径配置
  6. //var IMAGESPATH = 'http://www.5icool.org/'; //图片路径配置
  7. /*************************一些公用方法和属性****************************/
  8. var isIE = navigator.userAgent.indexOf('MSIE') != -1;
  9. var isIE6 = navigator.userAgent.indexOf('MSIE 6.0') != -1;
  10. var isIE8 = !!window.XDomainRequest && !!document.documentMode;
  11. if(isIE)
  12. try{ document.execCommand('BackgroundImageCache',false,true); }catch(e){}
  13. var $id = function (id) {
  14. return typeof id == "string" ? document.getElementById(id) : id;
  15. };
  16. //if (!$) var $ = $id;
  17. Array.prototype.remove = function (s, dust) { //如果dust为ture,则返回被删除的元素
  18. if (dust) {
  19. var dustArr = [];
  20. for (var i = 0; i < this.length; i++) {
  21. if (s == this[i]) {
  22. dustArr.push(this.splice(i, 1)[0]);
  23. }
  24. }
  25. return dustArr;
  26. }
  27. for (var i = 0; i < this.length; i++) {
  28. if (s == this[i]) {
  29. this.splice(i, 1);
  30. }
  31. }
  32. return this;
  33. }
  34. var $topWindow = function () {
  35. var parentWin = window;
  36. while (parentWin != parentWin.parent) {
  37. if (parentWin.parent.document.getElementsByTagName("FRAMESET").length > 0) break;
  38. parentWin = parentWin.parent;
  39. }
  40. return parentWin;
  41. };
  42. var $bodyDimensions = function (win) {
  43. win = win || window;
  44. var doc = win.document;
  45. var cw = doc.compatMode == "BackCompat" ? doc.body.clientWidth : doc.documentElement.clientWidth;
  46. var ch = doc.compatMode == "BackCompat" ? doc.body.clientHeight : doc.documentElement.clientHeight;
  47. var sl = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
  48. var st = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop); //考虑滚动的情况
  49. var sw = Math.max(doc.documentElement.scrollWidth, doc.body.scrollWidth);
  50. var sh = Math.max(doc.documentElement.scrollHeight, doc.body.scrollHeight); //考虑滚动的情况
  51. var w = Math.max(sw, cw); //取scrollWidth和clientWidth中的最大值
  52. var h = Math.max(sh, ch); //IE下在页面内容很少时存在scrollHeight<clientHeight的情况
  53. return {
  54. "clientWidth": cw,
  55. "clientHeight": ch,
  56. "scrollLeft": sl,
  57. "scrollTop": st,
  58. "scrollWidth": sw,
  59. "scrollHeight": sh,
  60. "width": w,
  61. "height": h
  62. }
  63. };
  64. var fadeEffect = function(element, start, end, speed, callback){//透明度渐变:start:开始透明度 0-100;end:结束透明度 0-100;speed:速度1-100
  65. if(!element.effect)
  66. element.effect = {fade:0, move:0, size:0};
  67. clearInterval(element.effect.fade);
  68. var speed=speed||20;
  69. element.effect.fade = setInterval(function(){
  70. start = start < end ? Math.min(start + speed, end) : Math.max(start - speed, end);
  71. element.style.opacity = start / 100;
  72. element.style.filter = "alpha(opacity=" + start + ")";
  73. if(start == end){
  74. clearInterval(element.effect.fade);
  75. if(callback)
  76. callback.call(element);
  77. }
  78. }, 20);
  79. };
  80. /*************************弹出框类实现****************************/
  81. var topWin = $topWindow();
  82. var topDoc = topWin.document;
  83. var Dialog = function () {
  84. /****以下属性以大写开始,可以在调用show()方法前设置值****/
  85. this.ID = null;
  86. this.Width = null;
  87. this.Height = null;
  88. this.URL = null;
  89. this.OnLoad=null;
  90. this.InnerHtml = ""
  91. this.InvokeElementId = ""
  92. this.Top = "50%";
  93. this.Left = "50%";
  94. this.Title = "";
  95. this.OKEvent = null; //点击确定后调用的方法
  96. this.CancelEvent = null; //点击取消及关闭后调用的方法
  97. this.ShowButtonRow = false;
  98. this.MessageIcon = "window.gif";
  99. this.MessageTitle = "";
  100. this.Message = "";
  101. this.ShowMessageRow = false;
  102. this.Modal = true;
  103. this.Drag = true;
  104. this.AutoClose = null;
  105. this.ShowCloseButton = true;
  106. this.Animator = true;
  107. /****以下属性以小写开始,不要自行改变****/
  108. this.dialogDiv = null;
  109. this.bgDiv=null;
  110. this.parentWindow = null;
  111. this.innerFrame = null;
  112. this.innerWin = null;
  113. this.innerDoc = null;
  114. this.zindex = 900;
  115. this.cancelButton = null;
  116. this.okButton = null;
  117. if (arguments.length > 0 && typeof(arguments[0]) == "string") { //兼容旧写法
  118. this.ID = arguments[0];
  119. } else if (arguments.length > 0 && typeof(arguments[0]) == "object") {
  120. Dialog.setOptions(this, arguments[0])
  121. }
  122. if(!this.ID)
  123. this.ID = topWin.Dialog._Array.length + "";
  124. };
  125. Dialog._Array = [];
  126. Dialog.bgDiv = null;
  127. Dialog.setOptions = function (obj, optionsObj) {
  128. if (!optionsObj) return;
  129. for (var optionName in optionsObj) {
  130. obj[optionName] = optionsObj[optionName];
  131. }
  132. };
  133. Dialog.attachBehaviors = function () {
  134. if (isIE) {
  135. document.attachEvent("onkeydown", Dialog.onKeyDown);
  136. window.attachEvent('onresize', Dialog.resetPosition);
  137. } else {
  138. document.addEventListener("keydown", Dialog.onKeyDown, false);
  139. window.addEventListener('resize', Dialog.resetPosition, false);
  140. }
  141. };
  142. Dialog.prototype.attachBehaviors = function () {
  143. if (this.Drag && topWin.Drag) topWin.Drag.init(topWin.$id("_Draghandle_" + this.ID), topWin.$id("_DialogDiv_" + this.ID)); //注册拖拽方法
  144. if (!isIE && this.URL) { //非ie浏览器下在拖拽时用一个层遮住iframe,以免光标移入iframe失去拖拽响应
  145. var self = this;
  146. topWin.$id("_DialogDiv_" + this.ID).onDragStart = function () {
  147. topWin.$id("_Covering_" + self.ID).style.display = ""
  148. }
  149. topWin.$id("_DialogDiv_" + this.ID).onDragEnd = function () {
  150. topWin.$id("_Covering_" + self.ID).style.display = "none"
  151. }
  152. }
  153. };
  154. Dialog.prototype.displacePath = function () {
  155. if (this.URL.substr(0, 7) == "http://" || this.URL.substr(0, 1) == "/" || this.URL.substr(0, 11) == "javascript:") {
  156. return this.URL;
  157. } else {
  158. var thisPath = this.URL;
  159. var locationPath = window.location.href;
  160. locationPath = locationPath.substring(0, locationPath.lastIndexOf('/'));
  161. while (thisPath.indexOf('../') >= 0) {
  162. thisPath = thisPath.substring(3);
  163. locationPath = locationPath.substring(0, locationPath.lastIndexOf('/'));
  164. }
  165. return locationPath + '/' + thisPath;
  166. }
  167. };
  168. Dialog.prototype.setPosition = function () {
  169. var bd = $bodyDimensions(topWin);
  170. var thisTop = this.Top,
  171. thisLeft = this.Left,
  172. thisdialogDiv=this.getDialogDiv();
  173. if (typeof this.Top == "string" && this.Top.substring(this.Top.length - 1, this.Top.length) == "%") {
  174. var percentT = this.Top.substring(0, this.Top.length - 1) * 0.01;
  175. thisTop = bd.clientHeight * percentT - thisdialogDiv.scrollHeight * percentT + bd.scrollTop;
  176. }
  177. if (typeof this.Left == "string" && this.Left.substring(this.Left.length - 1, this.Left.length) == "%") {
  178. var percentL = this.Left.substring(0, this.Left.length - 1) * 0.01;
  179. thisLeft = bd.clientWidth * percentL - thisdialogDiv.scrollWidth * percentL + bd.scrollLeft;
  180. }
  181. thisdialogDiv.style.top = Math.round(thisTop) + "px";
  182. thisdialogDiv.style.left = Math.round(thisLeft) + "px";
  183. };
  184. Dialog.setBgDivSize = function () {
  185. var bd = $bodyDimensions(topWin);
  186. if(Dialog.bgDiv){
  187. if(isIE6){
  188. Dialog.bgDiv.style.height = bd.clientHeight + "px";
  189. Dialog.bgDiv.style.top=bd.scrollTop + "px";
  190. Dialog.bgDiv.childNodes[0].style.display = "none";//让div重渲染,修正IE6下尺寸bug
  191. Dialog.bgDiv.childNodes[0].style.display = "";
  192. }else{
  193. Dialog.bgDiv.style.height = bd.scrollHeight + "px";
  194. }
  195. }
  196. };
  197. Dialog.resetPosition = function () {
  198. Dialog.setBgDivSize();
  199. for (var i = 0, len = topWin.Dialog._Array.length; i < len; i++) {
  200. topWin.Dialog._Array[i].setPosition();
  201. }
  202. };
  203. Dialog.prototype.create = function () {
  204. var bd = $bodyDimensions(topWin);
  205. if (typeof(this.OKEvent)== "function") this.ShowButtonRow = true;
  206. if (!this.Width) this.Width = Math.round(bd.clientWidth * 4 / 10);
  207. if (!this.Height) this.Height = Math.round(this.Width / 2);
  208. if (this.MessageTitle || this.Message) this.ShowMessageRow = true;
  209. var DialogDivWidth = this.Width + 13 + 13;
  210. var DialogDivHeight = this.Height + 33 + 13 + (this.ShowButtonRow ? 40 : 0) + (this.ShowMessageRow ? 50 : 0);
  211. if (DialogDivWidth > bd.clientWidth) this.Width = Math.round(bd.clientWidth - 26);
  212. if (DialogDivHeight > bd.clientHeight) this.Height = Math.round(bd.clientHeight - 46 - (this.ShowButtonRow ? 40 : 0) - (this.ShowMessageRow ? 50 : 0));
  213. var html = '\
  214. <table id="_DialogTable_' + this.ID + '" width="' + (this.Width + 26) + '" cellspacing="0" cellpadding="0" border="0" onselectstart="return false;" style="-moz-user-select: none; font-size:12px; line-height:1.4;">\
  215. <tr id="_Draghandle_' + this.ID + '" style="' + (this.Drag ? "cursor: move;" : "") + '">\
  216. <td width="13" height="33" style="background-image: url(' + IMAGESPATH + 'dialog_lt.png) !important;background: url(' + IMAGESPATH + 'dialog_lt.gif) no-repeat 0 0;"><div style="width: 13px;"></div></td>\
  217. <td height="33" style="background-image:url(' + IMAGESPATH + 'dialog_ct.png) !important;background: url(' + IMAGESPATH + 'dialog_ct.gif) repeat-x top;"><div style="padding: 9px 0 0 4px; float: left; font-weight: bold; color:#fff;"><img align="absmiddle" src="' + IMAGESPATH + 'icon_dialog.gif"/><span id="_Title_' + this.ID + '">' + this.Title + '</span></div>\
  218. <div onclick="Dialog.getInstance(\'' + this.ID + '\').cancelButton.onclick.apply(Dialog.getInstance(\'' + this.ID + '\').cancelButton,[]);" onmouseout="this.style.backgroundImage=\'url(' + IMAGESPATH + 'dialog_closebtn.gif)\'" onmouseover="this.style.backgroundImage=\'url(' + IMAGESPATH + 'dialog_closebtn_over.gif)\'" style="margin-top:5px; position: relative; cursor: pointer; float: right; height: 17px; width: 28px; background-image: url(' + IMAGESPATH + 'dialog_closebtn.gif);' + (this.ShowCloseButton ? "" : "display:none;") + '"></div></td>\
  219. <td width="13" height="33" style="background-image: url(' + IMAGESPATH + 'dialog_rt.png) !important;background: url(' + IMAGESPATH + 'dialog_rt.gif) no-repeat right 0;"><div style="width: 13px;"><a id="_forTab_' + this.ID + '" href="#;"></a></div></td>\
  220. </tr>\
  221. <tr valign="top">\
  222. <td width="13" style="background-image: url(' + IMAGESPATH + 'dialog_mlm.png) !important;background: url(' + IMAGESPATH + 'dialog_mlm.gif) repeat-y left;"></td>\
  223. <td align="center"><table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff">\
  224. <tr id="_MessageRow_' + this.ID + '" style="' + (this.ShowMessageRow ? "" : "display:none") + '">\
  225. <td valign="top" height="50"><table width="100%" cellspacing="0" cellpadding="0" border="0" style="background:#eaece9 url(' + IMAGESPATH + 'dialog_bg.jpg) no-repeat scroll right top;" id="_MessageTable_' + this.ID + '">\
  226. <tr>\
  227. <td width="50" height="50" align="center"><img width="32" height="32" src="' + IMAGESPATH + this.MessageIcon + '" id="_MessageIcon_' + this.ID + '"/></td>\
  228. <td align="left" style="line-height: 16px;"><div id="_MessageTitle_' + this.ID + '" style="font-weight:bold">' + this.MessageTitle + '</div>\
  229. <div id="_Message_' + this.ID + '">' + this.Message + '</div></td>\
  230. </tr>\
  231. </table></td>\
  232. </tr>\
  233. <tr>\
  234. <td valign="top" align="center"><div id="_Container_' + this.ID + '" style="position: relative; width: ' + this.Width + 'px; height: ' + this.Height + 'px;">\
  235. <div style="position: absolute; height: 100%; width: 100%; display: none; background-color:#fff; opacity: 0.5;" id="_Covering_' + this.ID + '">&nbsp;</div>\
  236. ' + (function (obj) {
  237. if (obj.InnerHtml) return obj.InnerHtml;
  238. if (obj.URL) return '<iframe width="100%" height="100%" frameborder="0" style="border:none 0;" allowtransparency="true" id="_DialogFrame_' + obj.ID + '" src="' + obj.displacePath() + '"></iframe>';
  239. return "";
  240. })(this) + '\
  241. </div></td>\
  242. </tr>\
  243. <tr id="_ButtonRow_' + this.ID + '" style="' + (this.ShowButtonRow ? "" : "display:none") + '">\
  244. <td height="36"><div id="_DialogButtons_' + this.ID + '" style="border-top: 1px solid #DADEE5; padding: 8px 20px; text-align: right; background-color:#f6f6f6;">\
  245. <input type="button" class="buttonStyle" value="确 定" id="_ButtonOK_' + this.ID + '"/>\
  246. <input type="button" class="buttonStyle" value="取 消" onclick="Dialog.getInstance(\'' + this.ID + '\').close();" id="_ButtonCancel_' + this.ID + '"/>\
  247. </div></td>\
  248. </tr>\
  249. </table></td>\
  250. <td width="13" style="background-image: url(' + IMAGESPATH + 'dialog_mrm.png) !important;background: url(' + IMAGESPATH + 'dialog_mrm.gif) repeat-y right;"></td>\
  251. </tr>\
  252. <tr>\
  253. <td width="13" height="13" style="background-image: url(' + IMAGESPATH + 'dialog_lb.png) !important;background: url(' + IMAGESPATH + 'dialog_lb.gif) no-repeat 0 bottom;"></td>\
  254. <td style="background-image: url(' + IMAGESPATH + 'dialog_cb.png) !important;background: url(' + IMAGESPATH + 'dialog_cb.gif) repeat-x bottom;"></td>\
  255. <td width="13" height="13" style="background-image: url(' + IMAGESPATH + 'dialog_rb.png) !important;background: url(' + IMAGESPATH + 'dialog_rb.gif) no-repeat right bottom;"><a onfocus=\'$id("_forTab_' + this.ID + '").focus();\' href="#;"></a></td>\
  256. </tr>\
  257. </table>\
  258. </div>\
  259. '
  260. var div = topWin.$id("_DialogDiv_" + this.ID);
  261. if (!div) {
  262. div = topDoc.createElement("div");
  263. div.id = "_DialogDiv_" + this.ID;
  264. topDoc.getElementsByTagName("BODY")[0].appendChild(div);
  265. }
  266. div.style.position = "absolute";
  267. div.style.left = "-9999px";
  268. div.style.top = "-9999px";
  269. div.innerHTML = html;
  270. if (this.InvokeElementId) {
  271. var element = $id(this.InvokeElementId);
  272. element.style.position = "";
  273. element.style.display = "";
  274. if (isIE) {
  275. var fragment = topDoc.createElement("div");
  276. fragment.innerHTML = element.outerHTML;
  277. element.outerHTML = "";
  278. topWin.$id("_Covering_" + this.ID).parentNode.appendChild(fragment)
  279. } else {
  280. topWin.$id("_Covering_" + this.ID).parentNode.appendChild(element)
  281. }
  282. }
  283. this.parentWindow = window;
  284. if (this.URL) {
  285. if (topWin.$id("_DialogFrame_" + this.ID)) {
  286. this.innerFrame = topWin.$id("_DialogFrame_" + this.ID);
  287. };
  288. var self = this;
  289. innerFrameOnload = function () {
  290. try {
  291. self.innerWin = self.innerFrame.contentWindow;
  292. self.innerWin.parentDialog = self;
  293. self.innerDoc = self.innerWin.document;
  294. if (!self.Title && self.innerDoc && self.innerDoc.title) {
  295. if (self.innerDoc.title) topWin.$id("_Title_" + self.ID).innerHTML = self.innerDoc.title;
  296. };
  297. } catch(e) {
  298. if (console && console.log) console.log("可能存在访问限制,不能获取到iframe中的对象。")
  299. }
  300. if (typeof(self.OnLoad)== "function")self.OnLoad();
  301. };
  302. if (this.innerFrame.attachEvent) {
  303. this.innerFrame.attachEvent("onload", innerFrameOnload);
  304. } else {
  305. this.innerFrame.onload = innerFrameOnload;
  306. };
  307. };
  308. topWin.$id("_DialogDiv_" + this.ID).dialogId = this.ID;
  309. topWin.$id("_DialogDiv_" + this.ID).dialogInstance = this;
  310. this.attachBehaviors();
  311. this.okButton = topWin.$id("_ButtonOK_" + this.ID);
  312. this.cancelButton = topWin.$id("_ButtonCancel_" + this.ID);
  313. div=null;
  314. };
  315. Dialog.prototype.setSize = function (w, h) {
  316. if (w && +w > 20) {
  317. this.Width = +w;
  318. topWin.$id("_DialogTable_" + this.ID).width = this.Width + 26;
  319. topWin.$id("_Container_" + this.ID).style.width = this.Width + "px";
  320. }
  321. if (h && +h > 10) {
  322. this.Height = +h;
  323. topWin.$id("_Container_" + this.ID).style.height = this.Height + "px";
  324. }
  325. this.setPosition();
  326. };
  327. Dialog.prototype.show = function () {
  328. this.create();
  329. var bgdiv = Dialog.getBgdiv(),
  330. thisdialogDiv=this.getDialogDiv();
  331. this.zindex = thisdialogDiv.style.zIndex = Dialog.bgDiv.style.zIndex + 1;
  332. if (topWin.Dialog._Array.length > 0) {
  333. this.zindex = thisdialogDiv.style.zIndex = topWin.Dialog._Array[topWin.Dialog._Array.length - 1].zindex + 2;
  334. } else {
  335. var topWinBody = topDoc.getElementsByTagName(topDoc.compatMode == "BackCompat" ? "BODY" : "HTML")[0];
  336. //topWinBody.styleOverflow = topWinBody.style.overflow; 去除滚动条
  337. //topWinBody.style.overflow = "hidden"; 去除滚动条
  338. bgdiv.style.display = "none";
  339. }
  340. topWin.Dialog._Array.push(this);
  341. if (this.Modal) {
  342. bgdiv.style.zIndex = topWin.Dialog._Array[topWin.Dialog._Array.length - 1].zindex - 1;
  343. Dialog.setBgDivSize();
  344. if(bgdiv.style.display == "none"){
  345. if(this.Animator){
  346. var bgMask=topWin.$id("_DialogBGMask");
  347. bgMask.style.opacity = 0;
  348. bgMask.style.filter = "alpha(opacity=0)";
  349. bgdiv.style.display = "";
  350. fadeEffect(bgMask,0,40,isIE6?20:10);
  351. bgMask=null;
  352. }else{
  353. bgdiv.style.display = "";
  354. }
  355. }
  356. }
  357. this.setPosition();
  358. if (this.CancelEvent) {
  359. this.cancelButton.onclick = this.CancelEvent;
  360. if(this.ShowButtonRow)this.cancelButton.focus();
  361. }
  362. if (this.OKEvent) {
  363. this.okButton.onclick = this.OKEvent;
  364. if(this.ShowButtonRow)this.okButton.focus();
  365. }
  366. if (this.AutoClose && this.AutoClose > 0) this.autoClose();
  367. this.opened = true;
  368. bgdiv=null;
  369. };
  370. Dialog.prototype.close = function () {
  371. var thisdialogDiv=this.getDialogDiv();
  372. if (this == topWin.Dialog._Array[topWin.Dialog._Array.length - 1]) {
  373. var isTopDialog = topWin.Dialog._Array.pop();
  374. } else {
  375. topWin.Dialog._Array.remove(this)
  376. }
  377. if (this.InvokeElementId) {
  378. var innerElement = topWin.$id(this.InvokeElementId);
  379. innerElement.style.display = "none";
  380. if (isIE) {
  381. //ie下不能跨窗口拷贝元素,只能跨窗口拷贝html代码
  382. var fragment = document.createElement("div");
  383. fragment.innerHTML = innerElement.outerHTML;
  384. innerElement.outerHTML = "";
  385. document.getElementsByTagName("BODY")[0].appendChild(fragment)
  386. } else {
  387. document.getElementsByTagName("BODY")[0].appendChild(innerElement)
  388. }
  389. }
  390. if (topWin.Dialog._Array.length > 0) {
  391. if (this.Modal && isTopDialog) Dialog.bgDiv.style.zIndex = topWin.Dialog._Array[topWin.Dialog._Array.length - 1].zindex - 1;
  392. } else {
  393. Dialog.bgDiv.style.zIndex = "900";
  394. Dialog.bgDiv.style.display = "none";
  395. var topWinBody = topDoc.getElementsByTagName(topDoc.compatMode == "BackCompat" ? "BODY" : "HTML")[0];
  396. //if (topWinBody.styleOverflow != undefined) topWinBody.style.overflow = topWinBody.styleOverflow; 去除滚动条
  397. }
  398. if (isIE) {
  399. /*****释放引用,以便浏览器回收内存**/
  400. thisdialogDiv.dialogInstance=null;
  401. if(this.innerFrame)this.innerFrame.detachEvent("onload", innerFrameOnload);
  402. this.innerFrame=null;
  403. this.parentWindow=null;
  404. this.bgDiv=null;
  405. if (this.CancelEvent){this.cancelButton.onclick = null;};
  406. if (this.OKEvent){this.okButton.onclick = null;};
  407. topWin.$id("_DialogDiv_" + this.ID).onDragStart=null;
  408. topWin.$id("_DialogDiv_" + this.ID).onDragEnd=null;
  409. topWin.$id("_Draghandle_" + this.ID).onmousedown=null;
  410. topWin.$id("_Draghandle_" + this.ID).root=null;
  411. /**end释放引用**/
  412. thisdialogDiv.outerHTML = "";
  413. CollectGarbage();
  414. } else {
  415. var RycDiv = topWin.$id("_RycDiv");
  416. if (!RycDiv) {
  417. RycDiv = topDoc.createElement("div");
  418. RycDiv.id = "_RycDiv";
  419. }
  420. RycDiv.appendChild(thisdialogDiv);
  421. RycDiv.innerHTML = "";
  422. RycDiv=null;
  423. }
  424. thisdialogDiv=null;
  425. this.closed = true;
  426. };
  427. Dialog.prototype.autoClose = function () {
  428. if (this.closed) {
  429. clearTimeout(this._closeTimeoutId);
  430. return;
  431. }
  432. this.AutoClose -= 1;
  433. topWin.$id("_Title_" + this.ID).innerHTML = this.AutoClose + " 秒后自动关闭";
  434. if (this.AutoClose <= 0) {
  435. this.close();
  436. } else {
  437. var self = this;
  438. this._closeTimeoutId = setTimeout(function () {
  439. self.autoClose();
  440. },
  441. 1000);
  442. }
  443. };
  444. Dialog.getInstance = function (id) {
  445. var dialogDiv = topWin.$id("_DialogDiv_" + id);
  446. if (!dialogDiv) alert("没有取到对应ID的弹出框页面对象");
  447. try{
  448. return dialogDiv.dialogInstance;
  449. }finally{
  450. dialogDiv = null;
  451. }
  452. };
  453. Dialog.prototype.addButton = function (id, txt, func) {
  454. topWin.$id("_ButtonRow_" + this.ID).style.display = "";
  455. this.ShowButtonRow = true;
  456. var button = topDoc.createElement("input");
  457. button.id = "_Button_" + this.ID + "_" + id;
  458. button.type = "button";
  459. button.style.cssText = "margin-right:5px";
  460. button.value = txt;
  461. button.onclick = func;
  462. var input0 = topWin.$id("_DialogButtons_" + this.ID).getElementsByTagName("INPUT")[0];
  463. input0.parentNode.insertBefore(button, input0);
  464. return button;
  465. };
  466. Dialog.prototype.removeButton = function (btn) {
  467. var input0 = topWin.$id("_DialogButtons_" + this.ID).getElementsByTagName("INPUT")[0];
  468. input0.parentNode.removeChild(btn);
  469. };
  470. Dialog.getBgdiv = function () {
  471. if (Dialog.bgDiv) return Dialog.bgDiv;
  472. var bgdiv = topWin.$id("_DialogBGDiv");
  473. if (!bgdiv) {
  474. bgdiv = topDoc.createElement("div");
  475. bgdiv.id = "_DialogBGDiv";
  476. bgdiv.style.cssText = "position:absolute;left:0px;top:0px;width:100%;height:100%;z-index:900";
  477. var bgIframeBox = '<div style="position:relative;width:100%;height:100%;">';
  478. var bgIframeMask = '<div id="_DialogBGMask" style="position:absolute;background-color:#333;opacity:0.4;filter:alpha(opacity=40);width:100%;height:100%;"></div>';
  479. var bgIframe = isIE6?'<iframe src="about:blank" style="filter:alpha(opacity=0);" width="100%" height="100%"></iframe>':'';
  480. bgdiv.innerHTML=bgIframeBox+bgIframeMask+bgIframe+'</div>';
  481. topDoc.getElementsByTagName("BODY")[0].appendChild(bgdiv);
  482. if (isIE6) {
  483. var bgIframeDoc = bgdiv.getElementsByTagName("IFRAME")[0].contentWindow.document;
  484. bgIframeDoc.open();
  485. bgIframeDoc.write("<body style='background-color:#333' oncontextmenu='return false;'></body>");
  486. bgIframeDoc.close();
  487. bgIframeDoc=null;
  488. }
  489. }
  490. Dialog.bgDiv = bgdiv;
  491. bgdiv=null;
  492. return Dialog.bgDiv;
  493. };
  494. Dialog.prototype.getDialogDiv = function () {
  495. var dialogDiv=topWin.$id("_DialogDiv_" + this.ID)
  496. if(!dialogDiv)alert("获取弹出层页面对象出错!");
  497. try{
  498. return dialogDiv;
  499. }finally{
  500. dialogDiv = null;
  501. }
  502. };
  503. Dialog.onKeyDown = function (event) {
  504. if (event.shiftKey && event.keyCode == 9) { //shift键
  505. if (topWin.Dialog._Array.length > 0) {
  506. stopEvent(event);
  507. return false;
  508. }
  509. }
  510. if (event.keyCode == 27) { //ESC键
  511. Dialog.close();
  512. }
  513. };
  514. Dialog.close = function (id) {
  515. if (topWin.Dialog._Array.length > 0) {
  516. var diag = topWin.Dialog._Array[topWin.Dialog._Array.length - 1];
  517. diag.cancelButton.onclick.apply(diag.cancelButton, []);
  518. }
  519. };
  520. Dialog.alert = function (msg, func, w, h) {
  521. var w = w || 300,
  522. h = h || 110;
  523. var diag = new Dialog({
  524. Width: w,
  525. Height: h
  526. });
  527. diag.ShowButtonRow = true;
  528. diag.Title = "系统提示";
  529. diag.CancelEvent = function () {
  530. diag.close();
  531. if (func) func();
  532. };
  533. diag.InnerHtml = '<table height="100%" border="0" align="center" cellpadding="10" cellspacing="0">\
  534. <tr><td align="right"><img id="Icon_' + this.ID + '" src="' + IMAGESPATH + 'icon_alert.gif" width="34" height="34" align="absmiddle"></td>\
  535. <td align="left" id="Message_' + this.ID + '" style="font-size:9pt">' + msg + '</td></tr>\
  536. </table>';
  537. diag.show();
  538. diag.okButton.parentNode.style.textAlign = "center";
  539. diag.okButton.style.display = "none";
  540. diag.cancelButton.value = "确 定";
  541. diag.cancelButton.focus();
  542. };
  543. Dialog.confirm = function (msg, funcOK, funcCal, w, h) {
  544. var w = w || 300,
  545. h = h || 110;
  546. var diag = new Dialog({
  547. Width: w,
  548. Height: h
  549. });
  550. diag.ShowButtonRow = true;
  551. diag.Title = "信息确认";
  552. diag.CancelEvent = function () {
  553. diag.close();
  554. if (funcCal) {
  555. funcCal();
  556. }
  557. };
  558. diag.OKEvent = function () {
  559. diag.close();
  560. if (funcOK) {
  561. funcOK();
  562. }
  563. };
  564. diag.InnerHtml = '<table height="100%" border="0" align="center" cellpadding="10" cellspacing="0">\
  565. <tr><td align="right"><img id="Icon_' + this.ID + '" src="' + IMAGESPATH + 'icon_query.gif" width="34" height="34" align="absmiddle"></td>\
  566. <td align="left" id="Message_' + this.ID + '" style="font-size:9pt">' + msg + '</td></tr>\
  567. </table>';
  568. diag.show();
  569. diag.okButton.parentNode.style.textAlign = "center";
  570. diag.okButton.focus();
  571. };
  572. Dialog.open = function (arg) {
  573. var diag = new Dialog(arg);
  574. diag.show();
  575. return diag;
  576. };
  577. if (isIE) {
  578. window.attachEvent("onload", Dialog.attachBehaviors);
  579. } else {
  580. window.addEventListener("load", Dialog.attachBehaviors, false);
  581. }