easyui.hp.myDialog.js
2.25 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
/**
* 显示一个对话框 继承与easyui的dialog 作者:黄平 日期:2012-10-17
*/
(function($) {
$.fn.myDialog = function(options, param) {
var self = this;
if (typeof (options) == "string") {
var method = $.fn.myDialog.methods[options];
if (method){
return method.call(this, param);
} else {
return this.dialog(options, param);
}
}
return this.each(function() {
var opt = $.extend({}, $.fn.myDialog.defaults, options);
var o = $.extend({}, opt);
if (o.closeOnEsc) {
o.onOpen = function() {
if (opt.onOpen) {
opt.onOpen();
}
closeSelf.call(self);
self.parent(".panel").focus();
};
} else {
o.onOpen = function() {
if (opt.onOpen) {
opt.onOpen();
}
self.parent(".panel").focus();
};
}
if (o.destoryOnClose) {
o.onClose = function () {
if (opt.onClose) {
opt.onClose();
}
try {
window.top.$(self).dialog("destroy");
} catch (e) {
window.$(self).dialog("destroy");
if (window.top) {
try {
window.top.$(self).dialog("destroy");
} catch (e) {
window.$(self).dialog("destroy");
}
} else {
$(self).dialog("destroy");
}
}
;
}
self.dialog(o);
}
});
};
$.fn.myDialog.methods = {
content : function(content) {
var jq = this;
if (content) {
return this.each(function() {
jq.dialog("body").find(".dialog-content").html(content);
});
} else {
return this.dialog("body").find("div.dialog-content").html();
}
},
title : function(title) {
var jq = this;
if (title) {
return this.each(function() {
jq.dialog("setTitle", title);
});
} else {
return this.dialog("header").find("div.panel-title").html();
}
}
};
function closeSelf() {
var self = $(this);
self.parent(".panel").keydown(function(e) {
if (e.keyCode == 27) {
if (window.parent) {
window.parent.$(self).myDialog("close");
} else {
$(self).myDialog("close");
}
}
});
}
$.fn.myDialog.event = {
onOpen : function() {
}
};
$.fn.myDialog.defaults = $.extend({}, $.fn.myDialog.event, {
closeOnEsc : true,
destoryOnClose : true,
openAnimation : "slide",
closeAnimation : "slide"
});
})(jQuery);