popup.js
2.55 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
/**
* @author Administrator
*/
define( 'popup', function( require, exports ) {
var Popup = (function(){
var config = {
width : 300,
height : 200,
x : 0,
y : 0,
time : 0,
c_height : 0,
determine : function(){},
cancel : function(){},
data : null,
win : $(window),
isfooter : true,
isheader : true,
isrolling : false
};
var views = {
settle : function(data){
config = $.extend(config, data);
if(config.time > 0){isclose()};
if(config.isrolling){
config.win = $(document);
};
config.y = (config.win.height() - config.height) / 2;
config.x = (config.win.width() - config.width) / 2;
if(config.isheader){
config.c_height = config.height - 40;
}else{
config.c_height = config.height;
};
this.show();
},
isclose : function(){
var time = setTimeout(function () {
clearTimeout(time);
$('.n-popup .cancel').click();
}, config.time);
},
show : function(){
$("body .n-popup").remove();//清理原有的
var content = "";
if(config.url){
content = '<iframe src="'+config.url+'" frameborder="no" border="0" allowTransparency="true" ></iframe>';
}else if(config.content){
content = config.content;
};
var btns = '<a href="#" class="save" >确定</a><a href="#" class="cancel" >取消</a>';
var view = '<div class="n-popup" style="'+(config.isrolling ? "position:absolute" : "")+'">'
+'<div class="background" style="'+(config.isrolling ? "position:fixed" : "")+'"></div>'
+'<div class="n-popup-cont" style="width:'+config.width+'px;height:'+config.height+'px;'
+'left:'+config.x+'px;top:'+config.y+'px;" >'+(! config.isheader ? '' : '<div class="n-popup-cont-header">'
+'<p>'+config.title+'</p><a href="#" class="cancel colse"></a></div>')+'<div class="n-popup-cont-content"'
+' style="height:'+config.c_height+'px;'+(!config.isheader ? 'top:6px;': 'top:47px;')+'" >'+content+'</div>'
+'<div class="n-popup-cont-footer" '+(config.isfooter ? '' : 'style="display: none;"')+' >'
+btns+'</div></div></div>';
$('body').append(view);
this.events();
},
events : function(){
$('.n-popup .cancel').click(function(){
config.cancel();
$('.n-popup').remove();
return false;
});
$('.n-popup .save').click(function(){
config.determine();
$('.n-popup').remove();
return false;
});
}
};
this.start = function(data){
views.settle(data);
};
return this;
})();
return Popup;
});