util.js
2.17 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
/**
* util.js
*
* depend on init.jsp, jquery, bootstrap, bootbox
*/
(function($, window, document,undefined) {
var ModalContainer = [];
//定义Modal的构造函数
var Modal = function(opt) {
this.options = opt
}
//定义Modal的方法
Modal.prototype = {
showLoading: function() {
var _options = $.extend({closeButton: false, message: 'Loading...'}, this.options);
_options.message = '<div class="text-center"><img src="'+Main.contextPath+'/static/images/loading.gif" style="margin-right: 10px;">'+_options.message+'</div>';
var _modal = bootbox.dialog(_options);
ModalContainer.push(_modal);
return _modal;
},
hideLoading: function() {
var _modal = null;
while((_modal = ModalContainer.pop())){
_modal.modal('hide');
}
},
hideAll: function() {
bootbox.hideAll();
},
alert: function(opt, callback) {
if(callback){
bootbox.alert(opt, callback);
} else {
bootbox.alert(opt);
}
}
}
//在插件中使用Modal对象
$.extend({
showLoading : function(options) {
if(options){
if(typeof options == 'string'){
options = {message : options};
}
}
//创建Modal的实体
var modal = new Modal(options);
//调用其方法
return modal.showLoading();
},
hideLoading : function() {
var modal = new Modal();
return modal.hideLoading();
},
hideAllModals : function() {
var modal = new Modal();
return modal.hideAll();
},
alert : function(){
var argn = arguments.length;
var modal = new Modal();
if(argn == 1 && typeof arguments[0] == 'object'){
modal.alert(arguments[0]);
} else if (argn == 1 && typeof arguments[0] == 'string'){
modal.alert(arguments[0]);
} else if (argn == 2 && typeof arguments[0] == 'string' && $.isFunction(arguments[1])){
modal.alert(arguments[0], arguments[1]);
}
}
});
})(jQuery, window, document);