

1 var _hy = _hy || {};
2 _hy.Dialog = function (id,contentdiv)
3 {
4 this.Id;
5 this.MaskDiv;
6 this.MaskOpacity = 0.7;
7 this.MaskBg = "#000000";
8 this.IsShowMask = true;
9 this.Content = contentdiv;
10 this.Width;
11 this.Height;
12 this.pagesize;
13 }
14 _hy.Dialog.prototype.OnInit = function ()
15 {
16 this.pagesize = _hy.GetPageSize();
17 if(this.IsShowMask)
18 {
19 this.MaskDiv = _hy.GetId(this.Id+"Mask");
20 if(this.MaskDiv = undefined || this.MaskDiv == null)
21 {
22 var html = "<div id='"+this.Id+"Mask"+"' style='position: absolute; 100%; z-index: 2;top: 0px; left: 0px; background-color: "+this.MaskBg+"; filter: Alpha(opacity="+(this.MaskOpacity*100)+"); -moz-opacity: "+this.MaskOpacity+";opacity: "+this.MaskOpacity+"; display:none'></div>";
23 document.writeln(html);
24 this.MaskDiv =_hy.GetId(this.Id+"Mask");
25
26 this.MaskDiv.style.height = (this.pagesize[1]+170)+"px";
27 this.MaskDiv.style.width = this.pagesize[0]+"px";
28
29 }
30 }
31
32 if (this.Content.style.width != "")
33 this.Width = parseInt(this.Content.style.width);
34 else
35 this.Width =500;
36 if (this.Content.style.height != "")
37 this.Height = parseInt(this.Content.style.height);
38 else
39 this.Content.style.top = "100px";
40
41 if(this.Width != undefined)
42 this.Content.style.width = this.Width+"px";
43 if(this.Height != undefined)
44 this.Content.style.height = this.Height+"px";
45
46 this.Content.style.zIndex=3;
47 this.Content.style.position = "absolute";
48 this.Content.style.display = "none";
49
50 if(this.Content.style.left == "")
51 this.Content.style.left = (this.pagesize[2]-this.Width)/2 +"px";
52
53 if(this.Content.style.top == "")
54 this.Content.style.top = (this.pagesize[3]-this.Height)/2+"px";
55
56 }
57
58 _hy.Dialog.prototype.Toggle = function ()
59 {
60 if(this.Content.style.display == "none")
61 {
62 this.Content.style.display = "";
63 if(this.MaskDiv != undefined)
64 {
65 this.MaskDiv.style.display = "";
66 }
67 }
68 else
69 {
70 this.Content.style.display = "none";
71 if(this.MaskDiv != undefined)
72 {
73 this.MaskDiv.style.display = "none";
74 }
75 }
76 }
使用方法
var dialog = new _hy.Dialog("dialog",_hy.GetId("dialogPanel"));
dialog.MaskOpacity = 0.6;
dialog.OnInit();
function SelectCategory_Click()
{
dialog.Toggle();
}
function SelectCategory_Close()
{
dialog.Toggle();
}