dialog.js
3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* @fileOverview 弹出对话框组件
* @author:Hbomb(zhouqq@yoho.cn)
* @date:2012-08-28
*/
define('dialog', function(require, exports)
{
var $ = require("jquery");
//初始化
var _init = function(opts)
{
/**
* 配置
*
*/
var opt =
{
con:"",
title: null, //标题,如果需要显示标题,则传递标题名称即可
buttons:'',
noclose:false,
id:null,
alpha:30,
zindex:9999
};
$.extend(opt, opts);
if(!opt.noclose)
{
exports.close();
}
var idstr = opt.id?('id="'+opt.id+'"'):"";
var idmaskstr = opt.id?('id="'+opt.id+'mask"'):"";
$("body").append('<div class="windows" '+idstr+'" style="position:absolute;z-index:'+(opt.zindex+1)+'">'+
'<div class="rel_title">'+
'<div class="rel_title_ico"><strong style="padding-left:24px;"></strong></div>'+
'<a href="javascript:void(0)" class="rel_title_close"></a>'+
'</div><div class="rel_content"></div></div>');
$("body").append('<div class="d-mask" '+idmaskstr+' style="top:0;left:0;width:100%;position:absolute;z-index:'+opt.zindex+';background:#000;filter:alpha(opacity='+
opt.alpha+');opacity:'+(opt.alpha/100)+';position:absolute;"></div>');
obj = opt.id?$("#"+opt.id):$(".windows");
if(opt.width)
{
obj.width(opt.width);
}
if(opt.con)
{
obj.find(".rel_content").append(opt.con);
}
if(opt.buttons)
{
obj.append(opt.buttons);
}
//处理标题
if(opt.title)
{
var title = opts.title;
obj.find('.rel_title strong').text(title);
}
obj.find(".rel_title_close").click(function()
{
exports.close(opt.id);
});
_setPos(obj);
$(window).bind('resize',function(){_setPos(obj);});
};
exports.setPos = function(obj)
{
_setPos(obj);
};
exports.setMask = function(obj,eh)
{
var h = obj.offset().top+obj.height();
h = eh?(h+eh):h;
var height = h>$(document).height()?h:$(document).height();
$(".d-mask").css(
{
"width":"100%",
"height":height+"px",
"top":"0",
"left":"0"
});
};
var _setPos = function(obj)
{
var w = $(window).width();
var t = $(window).scrollTop();
var h = $(window).height();
var ww = obj.width();
var hh = obj.height();
var top = h/2-hh/2;
top = top<0?0:top;
obj.css(
{
"top":(top+t)+"px",
"left":(w/2-ww/2)+"px"
});
if(!($.browser.msie&&$.browser.version=='6.0'))
{
// obj.css({"position":"fixed"});
}
else
{
obj.css(
{
"top":((h/2-hh/2)+t)+"px"
});
}
exports.setMask(obj);
};
//开启对话框
exports.open = function(opt)
{
_init(opt);
};
//关闭对话框
exports.close = function(id)
{
if(id)
{
$("#"+id).remove();
$("#"+id+"mask").remove();
}
else
{
$(".windows").remove();
$(".d-mask").remove();
}
$(window).unbind('resize',_setPos);
};
});