bootstrap.alerts.js
1.52 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
/**
* 显示一个告警框
* 作者:黄平
* 日期:2016-04-11
*/
(function($) {
$.fn.alerts = function(options, param) {
var self = this;
if (typeof (options) == "string") {
var method = $.fn.alerts.methods[options];
if (method){
return method.call(this, param);
}
}
return this.each(function() {
var opt = $.extend({}, $.fn.alerts.defaults, options);
self.data("alerts", opt);
if (opt.url) {
$.ajax({
url : opt.url,
data : opt.queryParams,
type : opt.method,
dataType : opt.dataType,
success : function(data) {
}
});
} else {
_createAlerts.call(self, opt);
}
});
};
function _createAlerts(opt) {
var jq = this;
jq.empty();
jq.addClass("alert alert-"+ opt.type +" alert-dismissable");
var close = $("<button type='button' class='close'>").html("×").appendTo(jq);
close.click(function() {
jq.alerts("hide", "slow");
});
if (opt.content) {
jq.append(opt.content);
}
if (opt.showOnCreate === true) {
jq.alerts("show", "slow");
} else {
jq.alerts("hide", "slow");
}
}
$.fn.alerts.methods = {
hide : function(speed) {
var jq = this;
return this.each(function() {
jq.hide(speed);
jq.removeClass();
jq.empty();
});
},
show : function(speed) {
var jq = this;
return this.each(function() {
jq.show(speed);
});
}
};
$.fn.alerts.event = {
};
$.fn.alerts.defaults = $.extend({}, $.fn.alerts.event, {
content : "",
showOnCreate : true,
type : "info"
});
})(jQuery);