blob: 7d0a1cb46e3a997efb0cc3dfec61e7fadcbc600c [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* Modal Dialog Box
2 * copyright 8th July 2006 by Stephen Chapman
3 * http://javascript.about.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24function pageWidth() {
25 return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
26}
27function pageHeight() {
28 return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
29}
30function posLeft() {
31 return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
32}
33function posTop() {
34 return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
35}
36function getID(x) {
37 return document.getElementById(x);
38}
39function scrollFix() {
40 var obol=getID('ol');
41 obol.style.top=posTop()+'px';
42 obol.style.left=posLeft()+'px'
43}
44function sizeFix() {
45 var obol=getID('ol');
46 obol.style.height=pageHeight()+'px';
47 obol.style.width=pageWidth()+'px';
48}
49function kp(e) {
50 ky=e?e.which:event.keyCode;
51 if(ky==88||ky==120)CloseDlg();
52 return false
53}
54function inf(h) {
55// tag=document.getElementsByTagName('select');
56// for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
57 tag=document.getElementsByTagName('iframe');
58 for(i=tag.length-1; i>=0; i--)tag[i].style.visibility=h;
59 tag=document.getElementsByTagName('object');
60 for(i=tag.length-1; i>=0; i--)tag[i].style.visibility=h;
61}
62function ShowDlg(dlgID, wd, ht) {
63 var h='hidden';
64 var b='block';
65 var p='px';
66 var obol= document.getElementById('ol');
67 var obbxd = document.getElementById('mbd');
68 obbxd.innerHTML = getID(dlgID).innerHTML;
69 obol.style.height=pageHeight()+p;
70 obol.style.width=pageWidth()+p;
71 obol.style.top=posTop()+p;
72 obol.style.left=posLeft()+p;
73 obol.style.display=b;
74 var tp=posTop()+((pageHeight()-ht)/2)-12;
75 var lt=posLeft()+((pageWidth()-wd)/2)-12;
76 var obbx=getID('mbox');
77 obbx.style.top=(tp<0?0:tp)+p;
78 obbx.style.left=(lt<0?0:lt)+p;
79 obbx.style.width=wd+p;
80 obbx.style.height=ht+p;
81 inf(h);
82 obbx.style.display=b;
83 if("IE6" == GetBrowserType()) {
84 $("#mbd").bgiframe();
85 }
86
87 return false;
88}
89function CloseDlg() {
90 var v='visible';
91 var n='none';
92 getID('ol').style.display=n;
93 getID('mbox').style.display=n;
94 inf(v);
95 document.onkeypress=''
96}
97function initmb() {
98 var ab='absolute';
99 var n='none';
100 var obody=document.getElementsByTagName('body')[0];
101 var frag=document.createDocumentFragment();
102 var obol=document.createElement('div');
103 obol.setAttribute('id','ol');
104 obol.style.display=n;
105 obol.style.position=ab;
106 obol.style.top=0;
107 obol.style.left=0;
108 obol.style.zIndex=998;
109 obol.style.width='100%';
110 frag.appendChild(obol);
111 var obbx=document.createElement('div');
112 obbx.setAttribute('id','mbox');
113 obbx.style.display=n;
114 obbx.style.position=ab;
115 obbx.style.zIndex=999;
116 var obl=document.createElement('span');
117 obbx.appendChild(obl);
118 var obbxd=document.createElement('div');
119 obbxd.setAttribute('id','mbd');
120 obl.appendChild(obbxd);
121 frag.insertBefore(obbx,obol.nextSibling);
122 obody.insertBefore(frag,obody.firstChild);
123 window.onscroll = scrollFix;
124 window.onresize = sizeFix;
125}
126