common.js
3.58 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
/**
* Created by mac on 17/5/8.
*/
//获取url后面参数
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
};
//弹窗
;(function() {
var Pop = function(config) {
var _this_ = this;
//默认配置
this.config = {
width: "380px",
header: "",
content: "",
buttons: null,
footCustom: null
};
//默认参数扩展
if(config && $.isPlainObject(config)) {
$.extend(this.config, config)
}
this.body = $("body");
this.mask = $('<div class="popMask"></div>');
this.win = $('<div class="popWin ITD-border-radius"></div>');
this.title = $('<div class="popTitle"></div>');
this.titleText = $('<span class="popText"></span>');
this.closed = $('<span class="popClose close ITD-model-close">x</span>');
this.content = $('<div class="popContent"></div>');
this.footer = $('<div class="popFooter"></div>');
this.create();
};
Pop.prototype = {
create: function() {
var _this_ = this;
var config = this.config,
body = this.body,
mask = this.mask,
win = this.win,
title = this.title,
titleText = this.titleText,
closed = this.closed,
content = this.content,
footer = this.footer;
//关闭事件
closed.click(function(){
_this_.close();
})
//添加title
if(config.header != "" && typeof config.header != "string") {
title.append(titleText.append(config.header));
title.append(closed);
win.append(title);
} else {
title.append(titleText.html(config.header));
title.append(closed);
win.append(title);
}
//添加内容
if(config.content != "" && typeof config.content != "string") {
win.append(content.append(config.content));
} else {
win.append(content.html(config.content));
}
//添加底部
if(config.footCustom != null) {
footer.append(footCustom);
} else if(config.buttons != null) {
$(config.buttons).each(function() {
var type = this.type ? this.type : "";
var btnText = this.text;
var callback = this.callback ? this.callback : null;
var button = $("<span class='" + type + "'>" + btnText + "</span>");
if(callback) {
button.click(function() {
callback();
});
} else {
button.click(function() {
_this_.close();
})
}
footer.append(button)
});
}
win.append(footer);
if(config.width != "300px") {
mask.append(win.width(config.width));
} else {
mask.append(win);
}
mask.css("height", $(document).height());
body.append(mask);
},
close: function() {
this.mask.remove();
}
}
window.Pop = Pop;
})(jQuery);