popup.js
3.99 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* @author Administrator
*/
var Popup = (function(){
var p_width = 300;
var p_height = 200;
var p_x = 0;
var p_y = 0;
var p_time = 5000;
var conentHeight = 0;
var formFun = null;
var cancelFun = null;
var callData = null;
/**
* 初始化
*/
function initialize (data){
$('body .n-popup').remove();//清理原有的
var content = '';
if(data.url){
content = '<iframe src="'+data.url+'" frameborder="no" border="0" allowTransparency="true" ></iframe>';
}else if(data.content){
content = data.content;
}else{
content = '暂无内容';
};
var text1 = "确定";
var text2 = "取消";
var _btnView = '';
if(data.btns){
if(data.btns.length == 1){
text1 = data.btns[0];
_btnView = '<a href="#" class="save" >'+text1+'</a>';
}else{
text1 = data.btns[0];
text2 = data.btns[1];
_btnView = '<a href="#" class="save" >'+text1+'</a><a href="#" class="cancel" >'+text2+'</a>';
};
}else{
_btnView = '<a href="#" class="save" >'+text1+'</a>';
};
var view = '<div class="n-popup" style="'+(data.isrolling ? "position:absolute" : "")+'"><div class="background" style="'+(data.isrolling ? "position:fixed" : "")+'"></div><div class="n-popup-cont" style="width:'+p_width+'px;height:'+p_height+'px;left:'+p_x+'px;top:'+p_y+'px;" >'
+(data.hideheaderBar ? '' : '<div class="n-popup-cont-header"><p>'+data.title+'</p><a href="#" class="cancel colse"></a></div>')
+'<div class="n-popup-cont-content" style="height:'+conentHeight+'px;'+(data.hideheaderBar ? 'top:0px;': 'top:47px;')+'" >'+content+'</div>'
+'<div class="n-popup-cont-footer" '+(data.hidefooterBar ? '' : 'style="display: none;"')+' >'+_btnView+'</div></div></div>';
/*var $view = $(view);
if($view.find("img").size() > 0){
$view.find("img").each(function(){
$(this).lazyload({
effect : "fadeIn",
skip_invisible : false
});
});
}
$('body').append($view);*/
$('body').append(view);
eventListeners();
};
/**
* 事件监听区
*/
function eventListeners (){
$('.n-popup .cancel').click(function(){
if(cancelFun){
cancelFun(callData);
};
$('.n-popup').remove();
return false;
});
$('.n-popup .save').click(function(){
if(formFun){
formFun(callData);
};
return false;
});
};
/**
* 参数设置
*/
this.start = function(obj){
if(obj.time){
p_time = obj.time;
}
if(obj.cancelclick){
var time = setTimeout(function () {
clearTimeout(time);
$('.n-popup .cancel').click();
}, p_time);
};
if(obj.saveclick){
var time = setTimeout(function () {
clearTimeout(time);
$('.n-popup .save').click();
}, p_time);
};
if(obj.width){
p_width = obj.width;
};
if(obj.height){
p_height = obj.height;
};
var vWin = $(window);
if(obj.isrolling){
vWin = $(document);
};
p_y = (vWin.height() - p_height) / 2;
p_x = (vWin.width() - p_width) / 2;
if(obj.hidefooterBar){
conentHeight = p_height - 78;
}else{
conentHeight = p_height - 41;
};
if(obj.hideheaderBar){
conentHeight = conentHeight + 47;
};
if(obj.saveFun){
formFun = obj.saveFun;
};
if(obj.cancelFun){
cancelFun = obj.cancelFun;
};
//拼装页面
initialize(obj);
if(!obj.verification){
$('.n-popup .save').click(function(){
colse();
return false;
});
}
};
/**
* 设置数据
*/
this.setData = function(data){
callData = data;
};
this.colse = function(){
$('.n-popup').remove();
};
return this;
})();
function Alert(message, type, fun){
var message;
if(type == 'error') {//错误
message = '<p class="p-error"><span></span>'+message+'</p>';
}
else if(type == 'success') {//成功
message = '<p class="p-succeed"><span></span>'+message+'</p>';
}
else {//警告
message = '<p class="p-warning"><span></span>'+message+'</p>';
}
var fun;
Popup.start({
width:380,
height:240,
title : '温馨提示',
content : message,
saveFun: fun,
hidefooterBar:true,
hideheaderBar:false,
btns : ['确定']
});
}