dialog.js
3.57 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
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 13-6-4
* Time: 下午6:01
* To change this template use File | Settings | File Templates.
*/
define(function(require, exports, module){
var $ = require('jquery');
//require('css/dialog.css');
exports.open = function (opts){
/*
* 设置默认参数
* @content 弹出层显示的内容
* @title 弹出层标题
* @id 弹出层id
* @close 是否有关闭按钮
* @alpha 是否有遮罩层
* @zindex 弹出层显示的层级
* */
var opt = {
content: '',
id: '',
close: false,
alpha: 50,
zindex: 9999,
isSlider: false,
sliderId: '',
autoLayer: true
};
/*合并参数*/
$.extend(opt, opts);
var idStr = opt.id ? 'id="'+ opt.id +'"' : '';
var maskStr = opt.id ? 'id="'+ opt.id +'mask"' : 'id="mask"';
$('body').append('<div class="uiDialogLayer" '+ idStr +' style="z-index:'+ (opt.zindex+1) +'">' +
'<a href="javascript:;" class="closeLayer"></a>' +
'<div class="dialogContent"></div>' +
'</div> ');
if(opt.alpha){
$('body').append('<div class="maskBackground" '+ maskStr +' style="z-index:'+ opt.zindex +';opacity:'+ opt.alpha/100 +'; filter:alpha(opacity:'+ opt.alpha +');"></div> ');
}
$('#'+opt.id+'mask').height($(document).height());
var obj = opt.id ? $("#"+opt.id) : $('.uiDialogLayer');
opt.width && obj.width(opt.width);
opt.height && obj.height(opt.height);
opt.content && obj.find('.dialogContent').append(opt.content);
opt.buttons && obj.find('.dialogContent').append(opt.buttons);
obj.find('.closeLayer').click(function(){
exports.close(opt.id);
});
if(opt.autoLayer)
{
if($.browser.msie && $.browser.version == 6.0){
_setPos(obj);
$(window).bind('resize scroll', function(){
_setPos(obj);
});
}else{
obj.css({
position: 'fixed',
left: '50%',
top: '50%',
marginTop: -obj.height()/2,
marginLeft: -obj.width()/2
});
}
}else
{
_setPos(obj);
}
if(opt.isSlider){
exports.slider(opt.sliderId);
}
};
function _setPos(obj){
var clientWidth = $(window).width(),
clientHeight = $(window).height(),
scrollTop = $(window).scrollTop(),
dialogWidth = $(obj).outerWidth(),
dialogHeight = $(obj).outerHeight();
obj.css({
left: (clientWidth-dialogWidth)/2,
top: (clientHeight-dialogHeight)/2+scrollTop
});
}
exports.close = function(id){
if(id){
$('#'+id).remove();
$('#'+id+'mask').remove();
}else{
$('.uiDialogLayer').remove();
$('.maskBackground').remove();
}
}
exports.slider = function (id){
require.async('lib/ui/jquery.cycle', function(cycle){
$(id).before('<div class="activity-info-control" style="position:absolute; z-index: 9; left: 50%; bottom: 10px; margin: 0 0 0 -30px;"></div>').cycle({
fx: 'fade',
speed: 800,
timeout: 0,
pager: '.activity-info-control'
});
});
}
});