popup.js
2.64 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
/**
* @author Administrator
*/
var Popup = (function(){
var p_width = 600;
var p_height = 400;
var p_x = 0;
var p_y = 0;
var conentHeight = 0;
var formFun = null;
var cancelFun = null;
var callData = null;
var onStartFun = 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"><div class="background"></div><div class="n-popup-cont" style="width:'+p_width+'px;height:'+p_height+'px;left:'+p_x+'px;top:'+p_y+'px;" >'
+'<div class="n-popup-cont-header"><p>'+data.title+'</p><a href="#" class="colse cancel"></a></div>'
+'<div class="n-popup-cont-content" style="height:'+conentHeight+'px;" >'+content+'</div>'
+'<div class="n-popup-cont-footer" '+(data.isfooterBar ? '' : 'style="display: none;"')+' >'+_btnView+'</div></div></div>';
$('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.width){
p_width = obj.width;
};
if(obj.height){
p_height = obj.height;
};
p_y = ($(window).height() - p_height) / 2;
p_x = ($(window).width() - p_width) / 2;
if(obj.isfooterBar){
conentHeight = p_height - 96;
}else{
conentHeight = p_height - 41;
};
if(obj.saveFun){
formFun = obj.saveFun;
};
if(obj.cancelFun){
cancelFun = obj.cancelFun;
};
if(obj.onStartCallback && jQuery.isFunction(obj.onStartCallback)){
onStartFun = obj.onStartCallback;
onStartFun();
}
//拼装页面
initialize(obj);
};
/**
* 设置数据
*/
this.setData = function(data){
callData = data;
};
this.colse = function(){
$('.n-popup').remove();
};
return this;
})();